Basically, we are trying to figure out a way to return a query field value to a variable. We use the code shown below to set variables and try to return the value of a premade query's "QRY_NAME" field. With this value, we can then populate another build on the fly SELECT statement to populate another control's row source property.
I think this code should work, however, we get an error 3265 stating "item not found in this collection."
The error occurs with "FldValue = Qry!FldName.Value" (I denoted it with stars in the code.)
****************************************
Private Sub cbo_Letter_AfterUpdate()
Dim ProctorList As String
Dim DB As Database
Dim Qry As QueryDef
Dim FLD As Field
Dim FldName As String
Dim FldValue As String
Set DB = CurrentDb()
Set Qry = DB.QueryDefs!qry_Query_Name
FldName = Qry.Fields(2).Name
****FldValue = Qry!FldName.Value****
ProctorList = "SELECT " & FldValue & ".Proctor_ID, [" & FldValue & "]![Last_Name] & ', ' & [" & FldValue & "]![First_Name] AS Name FROM " & FldValue & ";"
cbo_Proctor.RowSource = ProctorList
cbo_Proctor.Requery
DB = Nothing
Qry = Nothing
End Sub
Is there another way to get the QRY_NAME value out of this query? Maybe through some simple SELECT statement tied to a variable name (we've tried this countless times, with no avail). Any help is greatly appreciated.
THANKS!!!!
I think this code should work, however, we get an error 3265 stating "item not found in this collection."
The error occurs with "FldValue = Qry!FldName.Value" (I denoted it with stars in the code.)
****************************************
Private Sub cbo_Letter_AfterUpdate()
Dim ProctorList As String
Dim DB As Database
Dim Qry As QueryDef
Dim FLD As Field
Dim FldName As String
Dim FldValue As String
Set DB = CurrentDb()
Set Qry = DB.QueryDefs!qry_Query_Name
FldName = Qry.Fields(2).Name
****FldValue = Qry!FldName.Value****
ProctorList = "SELECT " & FldValue & ".Proctor_ID, [" & FldValue & "]![Last_Name] & ', ' & [" & FldValue & "]![First_Name] AS Name FROM " & FldValue & ";"
cbo_Proctor.RowSource = ProctorList
cbo_Proctor.Requery
DB = Nothing
Qry = Nothing
End Sub
Is there another way to get the QRY_NAME value out of this query? Maybe through some simple SELECT statement tied to a variable name (we've tried this countless times, with no avail). Any help is greatly appreciated.
THANKS!!!!