Opening A query

Valentine

Member
Local time
Today, 04:15
Joined
Oct 1, 2021
Messages
261
My code looks like this:
Code:
strDataTagSrch = Me.cboDataTags.Value
Set dbCurr = Currentdb()
Set qdfCurr = dbCurr.QueryDefs(QueryName)
sqlStr = "stuff and things "
DoCmd.OpenQuery (queryName)

My query opens but there is no information in the query. The SQL statement works I created a query using it an the info appeared.
 
Code:
' ...
Set qdfCurr = dbCurr.QueryDefs(QueryName)
qdfCurr.SQL = "stuff and things "
DoCmd.OpenQuery (queryName)
' ...
 
Why are you trying to open a query to display the data in it? I would imagine you simply want to use the information inside the query to perform additional process, like search for files. No?
 
It is basically a search function for our users to use. I had it printing out as a report but the users would rather have a query so they can sort it and organize the information to research better. We have a field called "Data Tags" in each of our files with information and our users want to sort through all of our files that have a specific data tag.
 
Code:
' ...
Set qdfCurr = dbCurr.QueryDefs(QueryName)
qdfCurr.SQL = "stuff and things "
DoCmd.OpenQuery (queryName)
' ...
I added in the qdfCurr.SQL = sqlStr
My query gets updated with the new SQL every time but i have no data populating the query. The query opens which is what i want but it doesn't have any information and there should be. I ran a normal query with the SQL string from here and info was populated. Is there something i have to do before the DoCmd.OpenQuery?
 
Code:
' ...
Set qdfCurr = dbCurr.QueryDefs(QueryName)
sqlStr = "stuff and things "
Debug.Print sqlStr
qdfCurr.SQL = sqlStr
DoCmd.OpenQuery (queryName)
' ...

Then paste the output from the Immediate Window (Ctrl+G) here.
 
You might also try:
Code:
' ...
Set qdfCurr = dbCurr.QueryDefs(QueryName)
sqlStr = "stuff and things "
Debug.Print sqlStr
qdfCurr.SQL = sqlStr
dbCurr.QueryDefs.Refresh
DoCmd.OpenQuery (queryName)
' ...
 
Still no information and the print of my SQL was exactly what it needed to be.
 
I REALLY hate little things causing problems.....I had a space in between my * and variable inside the SQL so it wasnt finding any info with that as its tag.....
 
That's why I suggested posting your SQL here - many eyes can help spot such things!
 
NEVER, EVER open queries for the user to interact with. You have no control over what changes or deletions or additions they might make. Always use Forms (or reports) so that they can view the data and YOU can ensure that they don't modify any data incorrectly.

You can open forms in DS view that do not allow edits or deletions but the users can use the built in filtering options to filter the data if hthey want to.
 

Users who are viewing this thread

Back
Top Bottom