T
Thorson
I am very new to writing code and know very little.
I have a form that is used to enter parameters in for multiple reports and
queries, therefore there is multiple if-then-else statements in the code. The
first query (qryCurrentInventory2) relies upon the date (cboDate) and a
selection of 1 of 3 units (lstUnit) to run the query. I would like to make
it possible for the user to select more than 1 unit and have the query then
search for both those units.
I was looking at a website on how to write this code and I couldn't get it
to work. The code below is what I currently have, the list box (lstUnit) is
not functioning as a multi-select box and therefore only allows the user to
select one unit. If someone could give me a website to look at or help me
write it that'd be great!
The current code for this query is as follows (the entire code is listed
below that):
If IsNull(cboViewReport) Then
MsgBox "Please Select Report to View"
Else
Select Case cboViewReport
Case "Current Inventory"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenQuery "qryCurrentInventory2"
End If
The entire code for the form with all the options is as follows:
Private Sub cmdOK_Click()
If IsNull(cboViewReport) Then
MsgBox "Please Select Report to View"
Else
Select Case cboViewReport
Case "Current Inventory"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenQuery "qryCurrentInventory2"
End If
Case "Open Therapeutic Cases"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenReport "rptOpenTherapeuticCases", acViewPreview
End If
Case "Check Withdrawal Dates"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenReport "rptWithdrawalCheckDates", acViewPreview
End If
Case "Monthly Protocol Report"
If IsNull(txtDate) Or IsNull(cboMonth) Or IsNull(cboYear) Then
MsgBox "Please Select Current Inventory Date, Month and Year"
Else
DoCmd.OpenReport "rptMonthlyReportPG2Protocol", acViewPreview
End If
Case "Monthly Inventory Report"
If IsNull(txtDate) Or IsNull(lstUnit) Or IsNull(cboMonth) Or
IsNull(cboYear) Then
MsgBox "Please Select Current Inventory Date, Unit, Month and Year"
Else
Select Case lstUnit
Case "DSAC"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportDSAC"
Case "ORR"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportORR"
Case "URB"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportURB"
Case Else
MsgBox "Invalid entry in Unit"
End Select
End If
Case Else
MsgBox "Invalid entry in View Report"
End Select
End If
End Sub
I have a form that is used to enter parameters in for multiple reports and
queries, therefore there is multiple if-then-else statements in the code. The
first query (qryCurrentInventory2) relies upon the date (cboDate) and a
selection of 1 of 3 units (lstUnit) to run the query. I would like to make
it possible for the user to select more than 1 unit and have the query then
search for both those units.
I was looking at a website on how to write this code and I couldn't get it
to work. The code below is what I currently have, the list box (lstUnit) is
not functioning as a multi-select box and therefore only allows the user to
select one unit. If someone could give me a website to look at or help me
write it that'd be great!
The current code for this query is as follows (the entire code is listed
below that):
If IsNull(cboViewReport) Then
MsgBox "Please Select Report to View"
Else
Select Case cboViewReport
Case "Current Inventory"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenQuery "qryCurrentInventory2"
End If
The entire code for the form with all the options is as follows:
Private Sub cmdOK_Click()
If IsNull(cboViewReport) Then
MsgBox "Please Select Report to View"
Else
Select Case cboViewReport
Case "Current Inventory"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenQuery "qryCurrentInventory2"
End If
Case "Open Therapeutic Cases"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenReport "rptOpenTherapeuticCases", acViewPreview
End If
Case "Check Withdrawal Dates"
If IsNull(txtDate) Or IsNull(lstUnit) Then
MsgBox "Please Select Current Inventory Date and Unit"
Else
DoCmd.OpenReport "rptWithdrawalCheckDates", acViewPreview
End If
Case "Monthly Protocol Report"
If IsNull(txtDate) Or IsNull(cboMonth) Or IsNull(cboYear) Then
MsgBox "Please Select Current Inventory Date, Month and Year"
Else
DoCmd.OpenReport "rptMonthlyReportPG2Protocol", acViewPreview
End If
Case "Monthly Inventory Report"
If IsNull(txtDate) Or IsNull(lstUnit) Or IsNull(cboMonth) Or
IsNull(cboYear) Then
MsgBox "Please Select Current Inventory Date, Unit, Month and Year"
Else
Select Case lstUnit
Case "DSAC"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportDSAC"
Case "ORR"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportORR"
Case "URB"
DoCmd.RunMacro "mcrRunMonthlyInventoryReportURB"
Case Else
MsgBox "Invalid entry in Unit"
End Select
End If
Case Else
MsgBox "Invalid entry in View Report"
End Select
End If
End Sub