Assigning combo box value programmatically

R

Ray Silva

My stored query "MonthlyOutput" has 4 fields

SELECT "10315" AS FROM_CC_NBR, qryFinalAllocationPrintSIDESCopyMO.CCOUT AS
TO_CC_NBR, Sum(qryFinalAllocationPrintSIDESCopyMO.SidesToCC) AS ACTUAL_UNITS,
SumOfSidesbyMasterCopyMO.Month
FROM qryFinalAllocationPrintSIDESCopyMO INNER JOIN SumOfSidesbyMasterCopyMO
ON qryFinalAllocationPrintSIDESCopyMO.[Master-Sub] =
SumOfSidesbyMasterCopyMO.[Master-Sub]
GROUP BY "10315", qryFinalAllocationPrintSIDESCopyMO.CCOUT,
SumOfSidesbyMasterCopyMO.Month

The following function attempts to set the value of combo box cboSelectMonth
on Form MainForm programmatically so I can list the contents of the fields
and then send them to Excel

Sub OpenParamQuery()

Dim cmd As ADODB.Command
Dim prm As ADODB.Parameter
Dim rst As ADODB.Recordset

Set cmd = New ADODB.Command

With cmd
Set .ActiveConnection = CurrentProject.Connection
.CommandText = "MonthlyOutput"
.CommandType = adCmdStoredProc
End With

Set prm = cmd.CreateParameter("[Forms]![MainForm]![cboSelectMonth]",
adInteger)
cmd.Parameters.Append prm
cmd.Parameters("[Forms]![MainForm]![cboSelectMonth]").Value = 0
' whatever value I put in returns the same results...?
Set rst = cmd.Execute
Do Until rst.EOF
Debug.Print rst.Fields(3)
'this is the fourth field with the dates
rst.MoveNext
Loop

I'm not sure how this is supposed to work, or if the created parameter
should be adDate, but this does not do what I want, which is to let the user
select a month from the combo box and list the output for that month - which
I programmatically send to Excel.

The whole thing works great until I introduce the combo box parameter to the
query.

WHERE ((SumOfSidesbyMasterCopyMO.Month)=[Forms]![MainForm]![cboSelectMonth]))

I began posting this in another area, but after reading through a lot of
postings, it seems to me this is the most appropriate one...

Can anyone help me with this?
 

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