Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2007

Tip: Looking for answers? Try searching our database.

If else Statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nikki - 24 Sep 2007 18:42 GMT
I need help with this statement. It is looking at two text boxes and I want a
message to appear in a currently blank text box when conditions are met.

Private Sub Unit_Click()
If Me!TypeUnit = 1 Or 2 And Me!Totals > 15 Then
Me!Message = "Leak Rate Exceeded"
ElseIf Me!TypeUnit = 3 Or 4 And Me!Totals > 35 Then
Me!Message = "Leak Rate Exceeded"
Else
Me!Message = ""
End Sub

Thanks for the help!
Signature

Thanks,
Nikki

Douglas J. Steele - 24 Sep 2007 18:59 GMT
You're missing the End If, and you can't use Or like that in VBA.

Private Sub Unit_Click()
 If (Me!TypeUnit = 1 Or Me!TypeUnit = 2) And Me!Totals > 15 Then
   Me!Message = "Leak Rate Exceeded"
 ElseIf (Me!TypeUnit = 3 Or Me!TypeUnit = 4) And Me!Totals > 35 Then
   Me!Message = "Leak Rate Exceeded"
 Else
   Me!Message = ""
 End If
End Sub

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I need help with this statement. It is looking at two text boxes and I want
>a
[quoted text clipped - 10 lines]
>
> Thanks for the help!
Jim Burke in Novi - 24 Sep 2007 19:10 GMT
You have to code it as:

If (Me!TypeUnit = 1 Or Me!TypeUnit =2) And Me!Totals > 15 Then

You need the parentheses for this to work.

It's probably easier to use a Select statement here. Just code:

Select case Me!TypeUnit
  Case 1, 2
     If Me!Totals > 15 Then
        Me!Message = "Leak Rate Exceeded"
     End If
  Case 3, 4  
     If Me!Totals > 35 Then
        Me!Message = "Leak Rate Exceeded"
     End If
  Case Else
     Me!Message = vbnullstring
End Select

vbnullstring is a vb constant that represents "". It's slightly more
efficient to use it, since vb already has a variable defined to represent the
null string.

> I need help with this statement. It is looking at two text boxes and I want a
> message to appear in a currently blank text box when conditions are met.
[quoted text clipped - 9 lines]
>
> Thanks for the help!
Nikki - 24 Sep 2007 19:54 GMT
Thanks for the help- but when I put the new one in
Private Sub Unit_Click()
Select Case Me!TypeUnit
Case 1, 2
If Me!Totals > 15 Then
Me!Message = "Leak Rate Exceeded"
End If
Case 3, 4
If Me!Totals > 35 Then
Me!Message = "Leak Rate Exceeded"
End If
Case Else
Me!Message = vbNullString
End Select

It is still not working. Could there be something else I did wrong? I have
checked all the names- It is looking at a text box bound to an equation-is
that a problem?
Thanks again so much for the help!
Signature

Thanks,
Nikki

> You have to code it as:
>
[quoted text clipped - 34 lines]
> >
> > Thanks for the help!
Nikki - 24 Sep 2007 20:02 GMT
Ignore last post -
Thank you for the help it works great.
Signature

Thanks,
Nikki

> You have to code it as:
>
[quoted text clipped - 34 lines]
> >
> > Thanks for the help!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.