Retrieving data from table programmaticaly

W

Witchunter

Hi! I have a following problem:

I have a table called Dogs. It contains two fields, Class (textual,
represting dog class) and HasTail (Yes/No, representing if the dog has a
tail).

Next, I have a table called Tails. It contains only one field, Color
(textual, representing tail color).

Next, I have a form which I use to store some data in other table, which is
not relevant to all of this. On this form, I have placed two combo boxes.
One is always enabled, and it contains entries from table Dogs. It shows a
list of classes of dogs.
The second one is disabled by default, and should be enabled only if the
entry selected in the first one actually has a tail.

So lets say we have this in table Dogs:
Class HasTail
01. Labrador NO
02. Dalmatian YES
03. Puddle YES
04. Retriever NO
05. Bulldog NO

And this in table Tails:
Color
01. green
02. red
03. yellow
04. bluish

So, as I explained, I want to set second combo box enabled or disabled
depending on the choice selected in the first one.

I reckon the code would look something like this:

Private Sub Form_AfterUpdate()
Dim EntryHasTail As Boolean
Dim SomeObject As SomeObjectType // create some object
SomeObject = TableDogs.LookupEntryByName('Class', FirstComboBox.Text) //
assign object to entry in a table
EntryHasTail = SomeObject.HasTail // check if that entry has tail
SecondComboBox.Enabled = EntryHasTail
End Sub

Or is there a simpler solution to this?

How to find if an entry has a tail? Thanks in advance.
 
M

Mr B

Witchunter,

You can simple refer to the value of your first combo box to determine if
the second combo bos should be enabled or disabled.

Use the AfterUpdate event of the first combo box:

Private Sub Combo1_AfterUpdate()
If not isnull(me.Combo1) then
Me.Combo2.Enabled = True
Else
Me.Combo2.Enabled = False
End If
End Sub

Just replace the "Combo1" with the name of your first combo box and the
"Combo2" with the name of your second combo box.
 

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