>> QueryDef

  • Thread starter Thread starter Jonathan Parminter
  • Start date Start date
J

Jonathan Parminter

Hi, can you please tell me why the last line in this
snippet causes an error: Object Variable or With Block
variable not set

Dim strQueryName As String
Dim qdf As DAO.QueryDef

strQueryName = lstSelectReport.Column(2)
Set qdf = CurrentDb.QueryDefs(strQueryName)

Any ideas or suggestions appreciated :-)

Thanks
Jonathan
 
One possibility is that you don't have a 3 column listbox or more the third
column is a zero-length string or there is no row selected in the listbox or you
have the listbox set to allow multiple selections or there is no query with the
name you specified.

If you insert
Debug.Print strQueryName
after assigning a value to strQueryName
Do you get an error? Do you get the expected value?
 
Thanks John, using the debug tools I can confirm that the
variable, strQueryName does contain the name of a query.

I appologise as I forgot to mention that this is an Access
Project connected to a SQL back end.

Although I named the query:
qryEvaluationsComments

It is listed in the Queries tab of the database window as:
qryEvaluationsComments (dbo)

I have tried both names without success and also:
dbo.qryEvaluationsComments

I'm therefore not sure whether the problem is to do with
the name of the query or with the QueryDef object. I have
referenced the DAO object library.

Does this extra information make a difference?

Thanks
Jonathan
 
Jonathan Parminter said:
Thanks John, using the debug tools I can confirm that the
variable, strQueryName does contain the name of a query.

I appologise as I forgot to mention that this is an Access
Project connected to a SQL back end.

Although I named the query:
qryEvaluationsComments

It is listed in the Queries tab of the database window as:
qryEvaluationsComments (dbo)

I have tried both names without success and also:
dbo.qryEvaluationsComments

I'm therefore not sure whether the problem is to do with
the name of the query or with the QueryDef object. I have
referenced the DAO object library.

Does this extra information make a difference?

In an Access Data Project (ADP), there *is* no "current database", and
so CurrentDb() returns Nothing. I haven't done much with ADPs, but I'm
pretty sure you won't be able to use DAO to extract stored procedures or
views from the SQL Server back-end.
 
Thanks Dirk,

I was thinking that your answer was likely to be the case -
but I just hoped that it wasn't...

I'm sure there is a workable solution out there... it just
needs to be found :-)

Cheers
Jonathan
 
Back
Top