ListBoxes and Temp Tables

O

O Wilson

Hello,

I have a list box containing all 1 months. I also have a
report that details monthly billings.
I would like to allow the user the opportunity to select
as many months' records as they want to be
Included in another report called BillingReportSelected.

My code is as follows:
Private Sub Command4_Click()


Dim lst As Access.ListBox
Dim strMonth As String
Dim strCostCode As Double
Dim strCostCodeTotal As Double
Dim strPercentCompleteThisMonth As Double
Dim strThisMonth As Double
Dim strSumPercent As Double
Dim strSumThisMonth As Double
Dim varItem As Variant
Dim intIndex As Integer
Dim intCount As Integer
Dim intRow As Integer
Dim intColumn As Integer
Dim i As String
Dim lngID As String

Set lst = Forms![Form2]![LstSelectMonth]

DoCmd.SetWarnings False
strSQL = "DELETE * from tblMonths"
DoCmd.RunSQL strSQL

If lst.ItemsSelected.Count = 0 Then
MsgBox "Please select at least one month"
lst.SetFocus
Exit Sub
End If

For Each varItem In lst.ItemsSelected

strMonth = lst.Column(0, varItem)
Debug.Print "Selected ID: " & lngID
strSQL = "INSERT INTO tblMonths (Month, CostCode,
CostCodeTotal, " _
& "PercentCompleteThisMonth, ThisMonth,
SumPercent, SumThisMonth ) " _
& "SELECT Month, CostCode, CostCodeTotal,
PercentCompleteThisMonth, " _
& "ThisMonth, PercentCompleteThisMonth,
PercentCompleteThisMonth FROM BillingReport " _
& "WHERE Month = " & strMonth & ";"
DoCmd.RunSQL strSQL

Next varItem

DoCmd.OpenReport reportname:="BillingReportSelected",
View:=acViewPreview

ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox "ErrorNo: " & Err.Number & ": Description: " &
_
Err.Description
Resume ErrorHandlerExit

End Sub


When I click on the command button, I get a parameters
message box with the months I've selected in the message
area and a prompt to fill in the month. Each month I've
selected gets its own parameter message box. If I enter
the months I want, the report comes up as desired.

What have I done????? How can I get the months to be
entered via the list box and do away with the message
boxes?

My temp table is called tblMonths and I'm getting the
records from a query called BillingReport.

Thanks,

Owen
 

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