Running query from VBA with parameter

H

hbean

Hi -

I'm trying to run a query as part of a VBA procedure, and what I want
it to do is to grab the value for a parameter (the current month) from
another part of the procedure. I clearly am missing something,
however. Here's what I have:

Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
Dim strCurrentMonth As String
Dim strMsg As String
Dim qryPar As QueryDef

a bunch of stuff...

Set qryPar = db.QueryDefs("qryMonthlyAccrualUpdate")
qryPar.Parameters("Month") = rs3!Month
DoCmd.OpenQuery "qryMonthlyAccrualUpdate", acViewNormal

The value of rs3!Month should be whatever month's data they have just
entered (this is a database for tracking sick/annual accrual). The
query is designed to then calculate how many hours they have accrued
for that month and add it to a table so that their current balances
can be calculated. What is happening, however, is that I'm getting an
error that the rows can't be appended because of an access key
violation - I think this is because there isn't a value for the
month. I have both "month" and "ID" set as primary keys in the table.

Any help would be greatly appreciated. Also, if this is the wrong
forum for this message, I apologize.

TIA,
Heather
 

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