Problem with If Statement

David Ball

Registered User.
Local time
, 07:21
Joined
Aug 9, 2010
Messages
230
Hi, I have a problem with an If statement. If the value of Text7 is Null and the message is displayed I do not want the portion of code after End If to be processed.

How do I change my If statement to achieve this? Thanks very much.

Private Sub Command6_Click()
If IsNull(Me.Text7.Value) Then
MsgBox "You Need To Enter a Number in the Text Box", vbOKOnly
End If
Dim mySQL As String
mySQL = "SELECT tblItems.item, tblItems.quantity FROM tblItems WHERE (((tblItems.quantity)> + Text7.Value)); "
lstProducts.RowSource = mySQL
End Sub

Dave
 
If you want the code to stop, use Exit Sub:

Code:
Private Sub Command6_Click()
If IsNull(Me.Text7.Value) Then
    MsgBox "You Need To Enter a Number in the Text Box", vbOKOnly
    [COLOR="Red"]Exit Sub[/COLOR]
End If
Dim mySQL As String
mySQL = "SELECT tblItems.item, tblItems.quantity FROM tblItems WHERE (((tblItems.quantity)> + Text7.Value)); "
lstProducts.RowSource = mySQL
End Sub
 
If you want the code to stop, use Exit Sub:
Or (even better) put in the Else part.
Code:
Private Sub Command6_Click()
If IsNull(Me.Text7.Value) Then
    MsgBox "You Need To Enter a Number in the Text Box", vbOKOnly
[B][COLOR=Red]Else[/COLOR][/B]
   Dim mySQL As String
   mySQL = "SELECT tblItems.item, tblItems.quantity FROM tblItems WHERE (((tblItems.quantity)> + Text7.Value)); "
   lstProducts.RowSource = mySQL
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom