Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2007

Tip: Looking for answers? Try searching our database.

Running query from VBA with parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hbean - 05 Mar 2007 20:45 GMT
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
Allen Browne - 06 Mar 2007 00:12 GMT
Answered in comp.databases.ms-access
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.