Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If/Then/Else Statement

Status
Not open for further replies.

sstump

Technical User
Oct 29, 2003
56
US
I'm still farely new at coding in Access. So anything you could do to help would be grateful. I've got a simple form with a test box and a command button and two labels that are invisible. What I'm looking to do is this. When a user types a zip code in the text box and hits the command button (which I need to query the necessary Table), then I need the correct label to become visible.

This is what I've got please let me know how I need to get this to work.

If Text0 = [tables]![sheet1]![Zip_Codes] Then
Label3.Visible = True
Else:
Label4.Visible = True
End If

Do I need to build a query first and then how to a reference the If/Then statement to the query.

Please help.

Thanks,
Shawn
 
If you are just making the labels visible then you are on the right track. You might wanna look at if one label is visible making that invisible when the other one becomes visible. Like so:

Code:
If Text0 = [tables]![sheet1]![Zip_Codes] Then
    Label3.Visible = True
    [b]Label4.Visible = False[/b]
Else:
    Label4.Visible = True
    [b]Label3.Visible = False[/b]
End If

That should do it for ya.

If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmmv [pc1][shocked]
 
No luck. This is what I put in (it didn't like the or ):

Private Sub Command2_Click()
If Text0 = [tables]![sheet1]![Zip_Codes] Then
Label3.Visible = True
Label4.Visible = False
Else:
Label4.Visible = True
Label3.Visible = False
End If
End Sub

When I go into Debug Mode it highlights "If Text0 = [tables]![sheet1]![Zip_Codes] Then". Am I referencing the table correctly? Is there anything else I need to do to get it to identify the table. What you see above is my entire code for this function.

Thanks

 
Also when it highlights the &quot;If Text0 = [tables]![sheet1]![Zip_Codes] Then&quot;. When I run the cursor over the [Zip_Codes] it shows &quot;Tables!Sheets!ZipCodes=<Object required>&quot;. What does this mean?

Anyone?? Anyone??

Need to get this done today so any help you can give would be extremely helpful.
 
hi sstump,

if i understand correctly, you want to see if the zip code put in text0 matches a zip code in your table, right?

if so, then just referencing the table will not do it unless that is the ONLY zip code (record) on the table. (and i am not even sure that would do it)

try something like this below. what i am doing is performing a lookup on the table and checking to see if i get a match. if there is a match, a true result is returned, if not, false is returned.

i setup a table and form like you described and it worked for me. hope this helps.

'****start****
If DCount(&quot;[zip_codes]&quot;, &quot;sheet1&quot;, &quot;[zip_codes] ='&quot; & Forms!form4!Text0 & &quot;'&quot;) = 1 Then
Label3.Visible = True
Label4.Visible = False
Else:
Label4.Visible = True
Label3.Visible = False
End If
'****end******

Have A Great Day!!!, [bigglasses]

Nathan
Senior Test Lead
 
sstump;

What is happening is that you are referencing the combobox but in an if...then statement it has to be a specific zipcode for it to work right. Like this:

Private Sub Command2_Click()
If Text0.text = &quot;49440&quot; Then
Label3.Visible = True
Label4.Visible = False
Else:
Label4.Visible = True
Label3.Visible = False
End If
End Sub


If I take a peek in your Windows, to fix a problem, does that make me a &quot;Peeping Tom&quot;? Hmmmmmmmmmmv [pc1][shocked]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top