If - Else Statement

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
 
J

Jeff Boyce

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
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top