If Statement error

robbydogg

Registered User.
Local time
Today, 04:20
Joined
Jul 15, 2008
Messages
56
Hello,

I am using the below VB code to try and send a load of values from one form to another, but only if they are not nul. I run the code and it states "

Compile Error: Else without IF and highlights the first occurance of the Else statement.

Any help would be much appreciated :)


Private Sub Command320_Click()
On Error Resume Next
If Me.SrchID.Value > "" Then Forms!Frm_main!SrchID.Value = SrchID.Value
Else
Forms!Frm_main!SrchID.Value = "*"
End If
If SrchPR.Value > "" Then Forms!Frm_main!SrchPR.Value = SrchPR.Value
Else
Forms!Frm_main!SrchPR.Value = "*"
End If
If SrchLC.Value > "" Then Forms!Frm_main!SrchLC.Value = SrchLC.Value
Else
Forms!Frm_main!SrchLC.Value = "*"
End If
If SrchBR.Value > "" Then Forms!Frm_main!SrchBR.Value = SrchBR.Value
Else
Forms!Frm_main!SrchBR.Value = "*"
End If
If SrchCT.Value > "" Then Forms!Frm_main!SrchCT.Value = SrchCT.Value
Else
Forms!Frm_main!SrchCT.Value = "*"
End If
If SrchOC.Value > "" Then Forms!Frm_main!SrchOC.Value = SrchOC.Value
Else
Forms!Frm_main!SrchOC.Value = "*"
End If
If SrchDC.Value > "" Then Forms!Frm_main!SrchDC.Value = SrchDC.Value
Else
Forms!Frm_main!SrchDC.Value = "*"
End If
If SrchTR.Value > "" Then Forms!Frm_main!SrchTR.Value = SrchTR.Value
Else
Forms!Frm_main!SrchTR.Value = "*"
End If
End Sub





Kind thanks.
 
thanks for the info - whilst checking it out, i stumbled on the fact that i should have probably set it up slightly differently (by putting a new line after the Then statement), this now works:

Private Sub Command320_Click()
On Error Resume Next
If Me.SrchID.Value > "" Then
Forms!Frm_main!SrchID.Value = SrchID.Value
Else
Forms!Frm_main!SrchID.Value = "*"
End If
If SrchPR.Value > "" Then
Forms!Frm_main!SrchPR.Value = SrchPR.Value
Else
Forms!Frm_main!SrchPR.Value = "*"
End If
If SrchLC.Value > "" Then
Forms!Frm_main!SrchLC.Value = SrchLC.Value
Else
Forms!Frm_main!SrchLC.Value = "*"
End If
If SrchBR.Value > "" Then
Forms!Frm_main!SrchBR.Value = SrchBR.Value
Else
Forms!Frm_main!SrchBR.Value = "*"
End If
If SrchCT.Value > "" Then
Forms!Frm_main!SrchCT.Value = SrchCT.Value
Else
Forms!Frm_main!SrchCT.Value = "*"
End If
If SrchOC.Value > "" Then
Forms!Frm_main!SrchOC.Value = SrchOC.Value
Else
Forms!Frm_main!SrchOC.Value = "*"
End If
If SrchDC.Value > "" Then
Forms!Frm_main!SrchDC.Value = SrchDC.Value
Else
Forms!Frm_main!SrchDC.Value = "*"
End If
If SrchTR.Value > "" Then
Forms!Frm_main!SrchTR.Value = SrchTR.Value
Else
Forms!Frm_main!SrchTR.Value = "*"
End If
End Sub
 
Oki doki. Again, for legibility sake, space your IF blocks, i.e. enter a new line after every END IF so you can see your statements properly.

Glad it's working. :)
 

Users who are viewing this thread

Back
Top Bottom