using vb variable in Access2007 select query

smiler

Registered User.
Local time
Today, 12:51
Joined
Mar 24, 2011
Messages
10
Hi Friends,
I am having a problem with a Select query in Access 2007. In my database application in Access 2007, the select query is bound to a subform and I want the query to bring out records with the field in the WHERE clause equal to a module-level variable i have defined in VB code. eg.
Code:
 public mod_variable as integer
'
'I set the variable to a value later
mod_variable =2
'now the select query is like this
SELECT tbl_Music.genre, tbl_Music.album, tbl_Music.artist from tbl_Music 
WHERE tbl_Music.musicID=mod_variable;
 
You can't refer to a variable from a query. You would need to create a public function that returned the value of the variable, and use the function in the query.
 

Users who are viewing this thread

Back
Top Bottom