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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case statement using an IF statement

Status
Not open for further replies.

Jeremiah31

Programmer
Nov 7, 2006
31
US
Newbie, I was wondering if an "IF statement" can be included into a select case statement.

This is the original case statement

Dim strSQL As String

Select Case Index
Case 0
strTrailerId = Me.txtTrailerReq 'Set variable to trailer Number
strSQL = "sp_TRNS0004_TrailerTrackHistory_2 '" & strTrailerId & "'"
Case 1
lngReference = Me.txtReference
strSQL = "sp_TRNS0004_TrailerTrackHistoryByReference " & lngReference
Case 2
strBOL = Me.txtBol
strSQL = "sp_TRNS0004_TrailerTrackHistoryByBOL " & strBOL
End Select


Was wondering if something like this is possible:
Select Case Index
Case 0
If Me.txtTrailerReg is Null then
MsgBox("Data Enter error, must enter a Trailer Number before continuing")
Else
strTrailerId = Me.txtTrailerReq 'Set variable to trailer Number
strSQL = "sp_TRNS0004_TrailerTrackHistory_2 '" & strTrailerId & "'"
End IF

When I try to run the application I receive an error 404, How should this be handled?

 
Which line do you get the error on?

And what is the error: 404, but what about the error discription?


Have fun.

---- Andy
 
Code:
If Me.txtTrailerReg is Null then
should be
Code:
If IsNull(Me.txtTrailerReg) then
 
Except that....

txtTrailerReg appears to be a text box on the form, and the default property (.Text) of a text box can never be null, so the IsNull function would ALWAYS return false.

Perhaps this should really be...

Code:
If Trim(Me.txtTrailerReg.Text) = "" Then

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Unless this is in Access, in which case we often do check if a control is Null.


 
the program is VB6, i switch back and forth from Access and VB6 a lot, and really don't have that much experience with VB6. Still learning the basics, the main guru who was showing me the ropes left three weeks ago, so it's just me know. When I was reviewing case statement, I was wondering if a validation expression could be incorporated.
 
Unlike Access controls, VB6 controls don't have a Validation property where you enter an expression. Rather, they have a CausesValidation property, which if you set to True fires the control's Validate event, in which you would write code.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top