Passing a value from a module to a querydef

rglman

Registered User.
Local time
Today, 09:43
Joined
Jul 11, 2005
Messages
30
My database has a number of modules that import data from multiple Excel tables which I receive from multiple people. After using "DoCmd.TransferSpreadsheet" to load the data into the first 33 fields of a staging table (tbl_current_import), I update the 34th field with a value representing the company department of the person submitting the Excel sheet. I then execute a number of other queries to move the information from the staging table to the other db tables as needed. I have 56 modules each with the following code:

' Import the current template into the "tbl_current_import" table.
DoCmd.TransferSpreadsheet acImport, 8, "tbl_current_import", "\\myserver\myfolder\DeptName Budget Final.xls", False, "Budget Summary!a7:ag5007"

' Insert the Division_ID into position F34 of each record the "tbl_current_import" table.
DoCmd.RunSQL "UPDATE tbl_current_import SET tbl_current_import.F34 = ""13"" WHERE (((tbl_current_import.F1) Is Not Null)); ", -1

The only difference between the modules is the name of the Excel file and the value that gets plugged into field "F34".

I would like to replace the sql statement above with this querydef (qry_update_tbl_current_import):

UPDATE tbl_current_import SET tbl_current_import.F34 = [divID_Parameter]
WHERE (((tbl_current_import.F1) Is Not Null));

And, I would like to pass the querydef the parameter value for [divID_Parameter] from the module:

IE: 1. Open query "qry_update_tbl_current_import"
2. Set [divID_Parameter] = "13"
3. Execute & Close the query.

I am a total novice with vba and I need help with the syntax to do this.

Thanks in advance for your help!
 
I figured it out on my own...

Here's the sql for my update query querydef (qry_update_mytable):

UPDATE tbl_MyTable SET tbl_MyTable.F34 = [MyParam]
WHERE (((tbl_MyTable.F1) Is Not Null));


Here's the vba code for the module to update the empty field (F34):

Dim qdf As QueryDef

Set qdf = CurrentDb.QueryDefs("qry_update_mytable")
With qdf
.Parameters("MyParam") = 13
.Execute
End With
Set qdf = Nothing

Hope it helps others!
 

Users who are viewing this thread

Back
Top Bottom