If statements are driving me crazy

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a textbox [textbox] and i have a search button. I want it to be able to come up with an error message when nothing is entered in the textbax. From what i can remember i think the script goes along the lines of
if [textbox] = " " the
msgbox "You need to enter a value
else: (and it would continue with the rest

and before end sub i would put End if

Only prob is the form runs as if the if statement isn't there. I'll copy the statement for belo
--
Private Sub Command37_Click(

On Error GoTo Err_Command37_Clic


Dim stDocName As Strin
Dim stLinkCriteria As Strin


If "[Text35]=" & "'" The
MsgBox "You need to enter a name
DoCmd.Clos
Else

stDocName = "Details

stLinkCriteria = "[Surname]=" & "'" & Me![Text35] & "'
DoCmd.OpenForm stDocName, , , stLinkCriteri


Exit_Command37_Click

Exit Su
End I

Err_Command37_Click
MsgBox Err.Descriptio
Resume Exit_Command37_Clic

End Su

I just don't know what to do with this one. Any help will be very appreciate
 
Hi,
You had it right in your pseudo code example.
Are you sure you want the form to close though?
I'd just exit the sub to allow the user to enter some criteria

If Text35 = "" Then
MsgBox "You need to enter a name"
Exit Sub
End If

There's no need for an 'Else'


--
HTH
Dan Artuso, MVP


Alex said:
I have a textbox [textbox] and i have a search button. I want it to be
able to come up with an error message when nothing is entered in the
textbax. From what i can remember i think the script goes along the lines
of,
if [textbox] = " " then
msgbox "You need to enter a value"
else: (and it would continue with the rest)

and before end sub i would put End if.

Only prob is the form runs as if the if statement isn't there. I'll copy the statement for below
-->
Private Sub Command37_Click()

On Error GoTo Err_Command37_Click


Dim stDocName As String
Dim stLinkCriteria As String


If "[Text35]=" & "'" Then
MsgBox "You need to enter a name"
DoCmd.Close
Else:

stDocName = "Details"

stLinkCriteria = "[Surname]=" & "'" & Me![Text35] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Exit_Command37_Click:

Exit Sub
End If

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub


I just don't know what to do with this one. Any help will be very appreciated
 
If the form field is based on a field in a table or query you should also
check for the contents of the box being Null.

Ragnar
 
Back
Top