Open a form

G

Guest

I have a switchboard that has several combo boxes on used to filter a report
I want to open. I can't seam to get it to work. Can someone please look at
the string to find out what I am missing.

Private Sub CmdSearch_Click()
Dim stDocNameSearch As String
'Creating a Variant
Dim VarSo As Variant
Dim VarRMA As Variant
Dim VarAccNum As Variant
Dim VarPart As Variant
Dim VarSN As Variant
Dim VarLot As Variant

'Defining the Variant and what combox it is for
VarSo = Me!CmboSO
VarRMA = Me!CmboRMA
VarAccNum = Me!CmboAccNum
VarPart = Me!CmboPart
VarSN = Me!CmboSN
VarLot = Me!CmboLot

'all the reports names
stDocNameSO = "RMARequestSO"
stDocNameRMA = "RMARequestRMA"
stDocNameAccNum = "RMARequestAccNum"
stDocNamePart = "RMARequestPart"
stDocNameSN = "RMARequestSN"
stDocNameLot = "RMARequestLot"

'used to open the reports with a else if statment
If VarSo <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarRMA <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarAccNum <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarPart <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarSN <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

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

When I run the quiers they run fine. But when I run the reports the first
on only opens up correctly. The reset do not. If anyone has a better way
even it it is not a report maybe a form that would be great.
 
W

Wolfgang Kais

Hello Kat.

Kat said:
I have a switchboard that has several combo boxes on used to
filter a report I want to open. I can't seem to get it to work. Can
someone please look at the string to find out what I am missing.
[...]
'used to open the reports with a else if statment
If VarSo <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarRMA <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarAccNum <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarPart <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

ElseIf VarSN <> "" Then
DoCmd.OpenReport stDocNameSO, acViewPreview
'End If

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

When I run the quiers they run fine. But when I run the reports
the first one only opens up correctly. The rest do not. If anyone
has a better way even it it is not a report maybe a form that
would be great.

First problem: All "OpenReport" instructions open the same report.
Second problem: When using ElseIf, only one code block is executed.
Try this:

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

If VarRMA <> "" Then
DoCmd.OpenReport stDocNameRMA, acViewPreview
End If

If VarAccNum <> "" Then
DoCmd.OpenReport stDocNameAccNum, acViewPreview
End If

If VarPart <> "" Then
DoCmd.OpenReport stDocNamePart, acViewPreview
End If

If VarSN <> "" Then
DoCmd.OpenReport stDocNameSN, acViewPreview
End If

If VarLot <> "" Then
DoCmd.OpenReport stDocNameLot, acViewPreview
End If
 

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

Top