Help w/If-Then Statement

telco25

Registered User.
Local time
Today, 04:17
Joined
Feb 1, 2001
Messages
11
Hello,

I need some help on getting an IF-Then Statement to work. This is working off the OnChange in a Combo box. The user picks a company from the drop down list & I want the facilities table associated with this company to open. Here's my test code:
If Fac_tab = "BADGER" Then
DoCmd.OpenTable "BADGER_FAC", acViewNormal, acEdit

Else
If Fac_tab = "BB&W" Then
DoCmd.OpenTable "BBW_FAC", acViewNormal, acEdit
End If
End If

I also tried using Case, but no luck there either. Any help would be appreciated.

Thanks in advance.
 
Telco

The only things that leap out are ...

1. The line - Else
If Fac_tab = "BB&W" Then

Should read

Elseif Fac_tab = "BB&W" then

2. Is the name of the Combo box spelled correctly? Fac_tab

3. What is the BoundColumn of the Combo Box. If the combo box has a company id number column and a company name column (which is the common way you would see such a thing), then you will find that the displayed value in the CB may not be the value of the CB. The value would be the id number and the display would be the associated name. So you would have to say

If Fac_tab = 1 then ....

HTH
Chris
 
Thanks Chris,

I did try ElseIf and the name is spelled right. However, I'll try you're suggestion 3. Also not sure if it manners that this is an unbound combo box.

Thanks again.
 
Try it in the Before Update event of the control instead of the On Change. I think it will work as you want it from there.
 
Telco,
The on change event occurs when the text portion of a combo box changes.
You said you wanted to brind up the table when the user selects the combo box.
I think you want you code executed when the user selects it, which should be the on click event.

Skip
 
Yippee!

Thanks. Chris got me facing the right direction and Skip you hit it right on! It works great!!
 
Why not try:-

If Fac_tab = "BADGER" Then
DoCmd.OpenTable "BADGER_FAC", acViewNormal, acEdit
end if

If Fac_tab = "BB&W" Then
DoCmd.OpenTable "BBW_FAC", acViewNormal, acEdit
End If
 
Rob
This is what I did try in the first place and it didn't work. Chris was right with his suggestion on using the index. Since the index field was hidden I forgot all about it.

TFTH
Telco25
 

Users who are viewing this thread

Back
Top Bottom