Link to home
Create AccountLog in
Avatar of skennelly
skennelly

asked on

Passing An Argument Through a String - VBA

Is it possible to pass an argument through a string? I have the following code that I need to use for several different procedures, and am getting an error on the strSQL syntax. Thanks.

Public Sub SetDetailTotals(ByVal strValueName As String, ByVal strValueTotal As String)

Dim db As DAO.Database, rst As DAO.Recordset
Dim strSQL As String
Dim ID As Long

ID = Forms!frmSetsDetail!frmSetsDetailSub!SetsRepID

Set db = CurrentDb
strSQL = "SELECT tblSetsDetail.SetsRepID, tblSetsDetail(strValueName) FROM tblSetsDetail WHERE (((tblSetsDetail.SetsRepID)=" & ID & "));"
Set rst = db.OpenRecordset(strSQL)

I am getting the following error : Undefined function 'tblSetsDetail' in expression. Is it because of the argument is within a string statement? Solution - create a query for each rst? Thanks.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try this

strSQL = "SELECT tblSetsDetail.SetsRepID, tblSetsDetail.[" & strValueName &"] FROM tblSetsDetail WHERE (((tblSetsDetail.SetsRepID)=" & ID & "));"
Set rst = db.OpenRecordset(strSQL)
ASKER CERTIFIED SOLUTION
Avatar of Jez Walters
Jez Walters
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of skennelly
skennelly

ASKER

I tried both statments, and JezWalters worked. I was getting a 'False' error with capricorn1's statement. Thanks to you both though. I appreciate it.