Query with a variable

poporacer

Registered User.
Local time
Today, 04:27
Joined
Aug 30, 2007
Messages
136
I have a form (frmSearch) with a couple of listboxes (lstSearchName, lstSearchNickname).When the user double clicks an item in the listbox a new form opens up(frmInfo) that is populated by a query (qryRoster). From what I have found, is that you can not use a variable in a query but can reference a function. I can't get it to work. Here is what I have:

I have a module with this code:

Option Compare Database
Option Explicit
Public strQuery As String
Public Function GetName() As String
GetName = strQuery 'It doesn't seem like strQuery is available here
End Function

On the form I have:

Option Compare Database
Public strQuery As String

Private Sub lstSearchName_DblClick(Cancel As Integer)
strQuery = lstSearchName.Column(3) 'This works strQuery has the data
DoCmd.OpenForm "frmValidateInfo"
End Sub

^This should feed the variable (text data) to the query

The query is:
SELECT tblRoster.LName, tblRoster.FName, tblRoster.Address, tblRoster.City
FROM tblRoster
WHERE (tblRoster.LName)=getName();

What am I doing wrong?
 
As answered elsewhere, you've declared strQuery twice. Take it out of the form module.
 
Thanks,
I missed that....I searched the forum but to no avail!
 
No problem; I meant I answered your identical post on another site.
 

Users who are viewing this thread

Back
Top Bottom