If - Else Statement

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

Guest

I have a code that is not processing correctly. Can someone look at it to
see what I am missing. I have never done this kind of statement before.

Private Sub CmdSearch_Click()
Dim stDocNameSearch As String

Dim VarSo As Variant
Dim VarRMA As Variant
Dim VarAccNum As Variant
Dim VarPart As Variant
Dim VarSN As Variant
Dim VarLot As Variant

VarSo = Me!CmboSO
VarRMA = Me!CmboRMA
VarAccNum = Me!CmboAccNum
VarPart = Me!CmboPart
VarSN = Me!CmboSN
VarLot = Me!CmboLot

stDocNameSO = "RMARequestSO"
stDocNameRMA = "RMARequestRMA"
stDocNameAccNum = "RMARequestAccNum"
stDocNamePart = "RMARequestPart"
stDocNameSN = "RMARequestSN"
stDocNameLot = "RMARequestLot"

If VarSo <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

If VarRMA <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

If VarAccNum <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

If VarPart <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

If VarSN <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

If VarLot <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
Else

End Sub
 
Kat

"not processing correctly" could mean so many things, and maybe not even the
same to you as to us.

What do you want to have happen? What is happening instead?

And since it all starts with the data, please describe your data!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Assuming that Me!CmboSO, Me!CmboRMA and so on are combo boxes, and you're
trying to open reports based on what's been selected in each one, be aware
that a combo box with nothing selected returns Null, not "". You cannot
check for Null using operators such as = or <>: you must use the IsNull
function. Alternatively, if "" is a legitimate choice in the combo boxes,
you may wish to use

If Len(VarSo & vbNullString) > 0 Then

rather than
 
Back
Top