PDA

View Full Version : Solved: Simple issue but being driven mad No:1



dragon576
07-21-2006, 05:39 AM
Hi,
Got myself in a twist trying to get this working. Can now not see wood for the trees, mainly due to my lack of knowledge regarding structure.

Scenario is, several countries, which each have two main cities, and each city has two different streets.

Issue 1

I have a single Dropdown form field displaying countries. I have given this a bookmark as country.

Word document contains four tables. Each table has same the same text form fields as follows (I've used bookmarks with the same names).

City 1 (Bookmark name the same)
Site 1 (Bookmark name the same)
Site 2 (Bookmark name the same)

City 2 (Bookmark name the same)
Site 1 (Bookmark Site 3)
Site 2 (Bookmark Site 4)

If I select a country in the dropdown list, then I want the fields in each table to be populated with the same information. Eg, I select UK

Table 1

City1 = London
Site1 = Bond St
Site2 = Regent St
City2 = York
Site1 = High St
Site2 = Mill St

Table 2

City1 = London
Site1 = Bond St
Site2 = Regent St
City2 = York
Site1 = High St
Site2 = Mill St

table 3
same as table 1

table 4
same as table 1

Questions:

1. How do I select the Country and the select the relevent data (Tried using Cases and objects)
2. How do I then populate 6 formfields in each table with the same info. I'm guessing I use bookmarks.

I've not posted the actual code as it would confuse the issue (well it definitely confused me!).

Thanks

Doug
:dunno

matthewspatrick
07-21-2006, 08:19 AM
Doug,

I think you will find it much easier to implement this sort of thing in Access or Excel.

dragon576
07-30-2006, 10:39 AM
Managed to solve it once I had found my VB book and spend some time reading.

Next step, simplify and tidy up

Doug

-----------------------------


Sub SelectCountry()

'
' Select Country
'
Select Case ActiveDocument.FormFields("dpCountry").DropDown.Value
Case 1
'Country Site one
ActiveDocument.FormFields("txtCountry1").Result = "Vienna"
ActiveDocument.FormFields("txtTownA").Result = "A"
ActiveDocument.FormFields("txtTownB").Result = "B"
'Country Site two
ActiveDocument.FormFields("txtCountry2").Result = "Linz"
ActiveDocument.FormFields("txtTownC").Result = "C"
ActiveDocument.FormFields("txtTownD").Result = "D"

Case 2
'Country Site one
ActiveDocument.FormFields("txtCountry1").Result = "Prague"
ActiveDocument.FormFields("txtTownA").Result = "E"
ActiveDocument.FormFields("txtTownB").Result = "F"
'Country Site two
ActiveDocument.FormFields("txtCountry2").Result = "Centro"
ActiveDocument.FormFields("txtTownC").Result = "G"
ActiveDocument.FormFields("txtTownD").Result = "H"

Case 3
'Country Site one
ActiveDocument.FormFields("txtCountry1").Result = "Dortmund"
ActiveDocument.FormFields("txtTownA").Result = "I"
ActiveDocument.FormFields("txtTownB").Result = "J"
'Country Site two
ActiveDocument.FormFields("txtCountry2").Result = "Frankfurt"
ActiveDocument.FormFields("txtTownC").Result = "K"
ActiveDocument.FormFields("txtTownD").Result = "L"
Case 4
'Country Site one
ActiveDocument.FormFields("txtCountry1").Result = "Den Haag"
ActiveDocument.FormFields("txtTownA").Result = "M"
ActiveDocument.FormFields("txtTownB").Result = "N"
'Country Site two
ActiveDocument.FormFields("txtCountry2").Result = "Rotterdam"
ActiveDocument.FormFields("txtTownC").Result = "O"
ActiveDocument.FormFields("txtTownD").Result = "N"
End Select


End Sub

fumei
07-30-2006, 12:45 PM
Hi there. If I may suggest something to make entering your code easier.Dim oFF As FormFields
Set oFF = ActiveDocument.FormFieldsNow you can replace ActiveDocument.Formfields with oFF, as in:ActiveDocument.FormFields("txtCountry1").Result = "Dortmund"
ActiveDocument.FormFields("txtTownA").Result = "I"
ActiveDocument.FormFields("txtTownB").Result = "J"becomesoFF("txtCountry1").Result = "Dortmund"
oFF("txtTownA").Result = "I"
oFF("txtTownB").Result = "J"

dragon576
07-30-2006, 01:40 PM
I was planning to look at how to simplify the code with the possible use of objects, I did not know where to start so parked it while I look at another problem.

The biggest problem I find with the forums is trying to extract items of code from a bigger solution, without know which bits are required and what they do. A reply like this makes life a lot easier.

Many Thanks

Doug

fumei
07-30-2006, 08:48 PM
Well yes, it can be a little difficult to extract what you need. The key to that is to first clearly define your needs. Unfortunately, this is - by far - the hardest thing for people to do.

As an aside, I hope you realize thatSelect Case ActiveDocument.FormFields("dpCountry").DropDown.Valuedoes NOT process on the content of the dropdown.

Say you have a dropdown with:

France
Spain
Germany
England

The Select Case is NOT making any values on "France", "Spain" etc. .Value is the index of the dropdown, not the string.

dragon576
07-31-2006, 03:57 AM
Fumei,
I'm not quite sure what you mean by your last post. Does it make a difference, as it appears to work as it is? If so which statement should I use in it's place?


Thanks

Doug

fumei
07-31-2006, 09:14 PM
Oh, I am just mentioning because there may be an instance where you want to work with the string, rather than the index number.

For example. Suppose the dropdown list changes. Your code - using .Value - will always use the index number.

STARTING List:

France
Spain
Germany
England

and you add Italy, Greece and Poland. Then suppose you want to make it alphabetical.

ENDING List:
England
France
Germany
Greece
Italy
Poland
Spain

where before .Value = 1 meant France, now .Value = 1 means England. Value 4 meant England, now it means Greece. This is because, in reality, .Value does not mean anything but that number. It does not mean "France", or "England" or any string. It is a number.

Yes, it works using the number. And if you are never changing anything that is fine. Or if your logic does not require knowing what is the string value. But if it does....oFF("Dropdown1").DropDown. _
ListEntries(oFF("Dropdown1").DropDown.Value).Namegives the actual string value of the dropdown.

fumei
07-31-2006, 09:19 PM
What I am saying is that it may be a question of explicit values. If it is important to be explicit about something being "France"...not 1, or 4, or 5....then you should work with that explicit value.

Sometimes this is not needed, but other times it is. I mention this so that you - or others - know how to get that explicit value from a dropdown formfield.