WORD 2003 VBA TO READ ACCESS DATABASE 2003

J

JJ

Not sure if I should post this under word vba worc or access because
it involves both.

I have an access database where I have different fields having
relationships with other databases e.g. I have a field which is called
Branch then I have a relationship with a Branch table where in the
original database when you get to the Branch field you click on the
combobox in access and select a different branch (so its like a drop
down in the access database allowing you to select either CT, JHB or
DBN.

From word 2003 I am reading info from that database as follows:

strADNDB = "c:\apps\adndatabase.mdb"
strMASTPATH = ""
Set ADNDataBase = OpenDatabase(strADNDB) intRecords = "0"
Set rdAuthor = ADNDataBase.OpenRecordset("Author")
For intRecords = 0 To rdAuthor.RecordCount - 1
If rdAuthor.Fields(1).Value = Application.UserName Then
If rdAuthor.Fields(10).Value = "1" Then
OptionButton1.Value = True
End If
If rdAuthor.Fields(10).Value = "2" Then
OptionButton2.Value = True
End If
If rdAuthor.Fields(10).Value = "3" Then
OptionButton3.Value = True
End If
rdAuthor.MoveNext
Else
rdAuthor.MoveNext
End If
Next intRecords
rdAuthor.Close
ADNDataBase.Close

This works well but I battled to determine that the field value "1" is
actually JHB and field value "2" is CT and field value "3" is DBN.

I would want to have a different instruction where I can actually read
the text which is JHB or CT or DBN.

So it should say:
If rdAuthor.Fields(10).Value = "JHB" Then
OptionButton2.Value = True
End If
etc.

However, because the drop down is read from another table it uses a
number to see if you selected the first one in the list or the second
or the third.

For this option it is ok but my next step is where I have 200
departments and I will take hours to try and figure out which
department is actually which number.
Any ideas where I can maybe say If rdAuthor.Fields(10).Text or
TextValue or whatever is "JHB" Then .......

Hope you understand what I mean. Any help will be greatly appreciated.

Is there a way I can upload my database then you can see what I mean
if you don't understand.
 
D

Doug Robbins - Word MVP

You need to set the boundcolumn property of the dropdown to the column that
contains the information that you want to reference
 
J

JJ

You need to set the boundcolumn property of the dropdown to the column that
contains the information that you want to reference

--
Hope this helps,

Doug Robbins - Word MVP
dkr[atsymbol]mvps[dot]org




Not sure if I should post this under word vba worc or access because
it involves both.
I have an access database where I have different fields having
relationships with other databases e.g. I have a field which is called
Branch then I have a relationship with a Branch table where in the
original database when you get to the Branch field you click on the
combobox in access and select a different branch (so its like a drop
down in the access database allowing you to select either CT, JHB or
DBN.
From word 2003 I am reading info from that database as follows:
strADNDB = "c:\apps\adndatabase.mdb"
strMASTPATH = ""
Set ADNDataBase = OpenDatabase(strADNDB) intRecords = "0"
Set rdAuthor = ADNDataBase.OpenRecordset("Author")
For intRecords = 0 To rdAuthor.RecordCount - 1
   If rdAuthor.Fields(1).Value = Application.UserName Then
       If rdAuthor.Fields(10).Value = "1" Then
           OptionButton1.Value = True
       End If
       If rdAuthor.Fields(10).Value = "2" Then
           OptionButton2.Value = True
       End If
       If rdAuthor.Fields(10).Value = "3" Then
           OptionButton3.Value = True
       End If
       rdAuthor.MoveNext
   Else
       rdAuthor.MoveNext
   End If
Next intRecords
rdAuthor.Close
ADNDataBase.Close
This works well but I battled to determine that the field value "1" is
actually JHB and field value "2" is CT and field value "3" is DBN.
I would want to have a different instruction where I can actually read
the text which is JHB or CT or DBN.
So it should say:
       If rdAuthor.Fields(10).Value = "JHB" Then
           OptionButton2.Value = True
       End If
etc.
However, because the drop down is read from another table it uses a
number to see if you selected the first one in the list or the second
or the third.
For this option it is ok but my next step is where I have 200
departments and I will take hours to try and figure out which
department is actually which number.
Any ideas where I can maybe say If rdAuthor.Fields(10).Text or
TextValue or whatever is "JHB" Then .......
Hope you understand what I mean. Any help will be greatly appreciated.
Is there a way I can upload my database then you can see what I mean
if you don't understand.- Hide quoted text -

- Show quoted text -

Thank you so much Doug. Can't believe it was this easy. I tried to
post a "thank you" a while back but somehow the system wouldn't accept
my message. Thanx once again. You are a star.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top