Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

querydef problem

Status
Not open for further replies.

tboerner

Programmer
Oct 19, 2001
23
US
In the following code, I'm getting some inconsistent behavior. Sometimes, the Me.RecordSource says the qryOrganization is not found. This only happens sometimes. It appears to be a timing issue. I put in a loop between the 2 lines of code, that does nothing. This alleviates the problem, but does anyone have a better way?!

' Create QueryDef.
Set qryobjOrganization = appAccess.CreateQueryDef("qryOrganization", strSQL)

Me.RecordSource = "qryOrganization"
 
Have you tried querydefs.refresh for the currentdatabase object of appAccess' queydefs collection?
--Jim
 
Like this?

' Create QueryDef.
Set qryobjOrganization = appAccess.CreateQueryDef("qryOrganization", strSQL)

appAccess.Querydef.refresh

Me.RecordSource = "qryOrganization"
 
dear tboerner,

just give it go, I am not sure whether it helps:

Set qryobjOrganization = appAccess.currentdb.CreateQueryDef("qryOrganization", strSQL)

and/or this:

me.recordsource=appAccess.currentdb.CreateQueryDef("qryOrganization", strSQL).name

I am very keen to know if this helps

regards astrid
 
Astrid,

I did try:

Me.RecordSource = appAccess.CreateQueryDef("qryOrganization", strSQL).name

It doesn't solve the problem. There still seems to be a delay between when the Query is ready for use and when it is being assigned to the recordsource.

I did this and it works every time:

Set qryobjOrganization = appAccess.CreateQueryDef("qryOrganization", strSQL)

Dim a
a = 0
While a <= 10000000
a = a + 1
Wend

Me.RecordSource = &quot;qryOrganization&quot;
 

try this:
Set qryobjOrganization = appAccess.CreateQueryDef(&quot;qryOrganization&quot;, strSQL)

' qryobjorganization.movelast uncomment this, if the followig line does not solve

while qryobjorganization.stillexecuting
wend

Me.RecordSource = &quot;qryOrganization&quot;

regards
 
Astrid,

Neither of those worked. Movelast isn't available for a querydef. 'StillExecuting' appears as a possible method when you type 'qryobjOrganization', but when you run it, it says 'Operation is not supported.' That looked like a good idea.

I'm satisfied with my workaround. It has never failed, and if it does, they can just run again.

Thanks for your ideas. :)
 
dear tboerner,
another try:

Dim qryobjorganization As QueryDef

Set qryobjorganization = Access.Application.CurrentDb.CreateQueryDef(&quot;qryOrganization&quot;, strsql)

While CurrentProject.Connection.State = adStateExecuting
Wend

Me.RecordSource = &quot;qryOrganization&quot;

End Sub

regards astrid

(I do not like when access laughs at me :))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top