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!frmSet sDetailSub !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.
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!frmSet
Set db = CurrentDb
strSQL = "SELECT tblSetsDetail.SetsRepID, tblSetsDetail(strValueName
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
strSQL = "SELECT tblSetsDetail.SetsRepID, tblSetsDetail.[" & strValueName &"] FROM tblSetsDetail WHERE (((tblSetsDetail.SetsRepID
Set rst = db.OpenRecordset(strSQL)