Using Database Access Objects (DAO)

  • Thread starter George Papadopoulos
  • Start date
G

George Papadopoulos

I am trying to access the Jet data engine using DAO. Specifically I have
attached an event handler to a button on a form. The code is shown below :

Private Sub List_spares_Click()
On Error GoTo Err_cmdGoHere_Click

Dim stDocName As String
Dim dbLib As DATABASE
Dim qdfSpares As QueryDef

' Set dbLib to the current database
Set dbLib = CurrentDb

' Create a query
Set qdfSpares = dbLib.CreateQueryDef("Spares",
"SELECT * FROM ANTALLAKTIKA WHERE [Kwdikos episkeyhs] = 2")


stDocName = "LISTA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]



Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click

End Sub

The code is supposed to execute a query and return a recordset which is to
be displayed in another form. The code fails starting at the statement :
Dim dbLib As DATABASE. Do I need to do something else before I can access
the jet database engine using DAO?

Thanks in advance

George Papadopoulos
 
M

MacDermott

Well, you can do it by adding a reference to the DAO library.
From any code window, click Tools - References.
The DAO reference is there by default in Access 97, but not in later
versions.

But I have to wonder why you want to go programmatically creating a query
like that.
Why not just store it?
For one thing, that would keep you from having to delete it each time, after
creating it.

- Turtle
 
G

George Papadopoulos

thx, for the help. The query I need to use is actually a bit more
sophisticated than the one I posted. Specifically the parameter (e.t.c. 2 in
the posted query) needs to be read from another table. Then I wan`t to
create the inner join of these two tables based on the read value.

George Papadopoulos

Ï "MacDermott said:
Well, you can do it by adding a reference to the DAO library.
From any code window, click Tools - References.
The DAO reference is there by default in Access 97, but not in later
versions.

But I have to wonder why you want to go programmatically creating a query
like that.
Why not just store it?
For one thing, that would keep you from having to delete it each time, after
creating it.

- Turtle


George Papadopoulos said:
I am trying to access the Jet data engine using DAO. Specifically I have
attached an event handler to a button on a form. The code is shown below :

Private Sub List_spares_Click()
On Error GoTo Err_cmdGoHere_Click

Dim stDocName As String
Dim dbLib As DATABASE
Dim qdfSpares As QueryDef

' Set dbLib to the current database
Set dbLib = CurrentDb

' Create a query
Set qdfSpares = dbLib.CreateQueryDef("Spares",
"SELECT * FROM ANTALLAKTIKA WHERE [Kwdikos episkeyhs] = 2")


stDocName = "LISTA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]



Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click

End Sub

The code is supposed to execute a query and return a recordset which
is
to
be displayed in another form. The code fails starting at the statement :
Dim dbLib As DATABASE. Do I need to do something else before I can access
the jet database engine using DAO?

Thanks in advance

George Papadopoulos
 
M

MacDermott

There are still several ways to do this without actually re-creating the
query.
Would I be correct in my guess that your query "Spares" is the recordsource
of the form LISTA_ANTALLAKTIKWN?

= Turtle

George Papadopoulos said:
thx, for the help. The query I need to use is actually a bit more
sophisticated than the one I posted. Specifically the parameter (e.t.c. 2 in
the posted query) needs to be read from another table. Then I wan`t to
create the inner join of these two tables based on the read value.

George Papadopoulos

Ï "MacDermott said:
Well, you can do it by adding a reference to the DAO library.
From any code window, click Tools - References.
The DAO reference is there by default in Access 97, but not in later
versions.

But I have to wonder why you want to go programmatically creating a query
like that.
Why not just store it?
For one thing, that would keep you from having to delete it each time, after
creating it.

- Turtle
below
:
Private Sub List_spares_Click()
On Error GoTo Err_cmdGoHere_Click

Dim stDocName As String
Dim dbLib As DATABASE
Dim qdfSpares As QueryDef

' Set dbLib to the current database
Set dbLib = CurrentDb

' Create a query
Set qdfSpares = dbLib.CreateQueryDef("Spares",
"SELECT * FROM ANTALLAKTIKA WHERE [Kwdikos episkeyhs] = 2")


stDocName = "LISTA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]



Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click

End Sub

The code is supposed to execute a query and return a recordset which
is
to
be displayed in another form. The code fails starting at the statement :
Dim dbLib As DATABASE. Do I need to do something else before I can access
the jet database engine using DAO?

Thanks in advance

George Papadopoulos
 
G

George Papadopoulos

Exactly!!!

Ï "MacDermott said:
There are still several ways to do this without actually re-creating the
query.
Would I be correct in my guess that your query "Spares" is the recordsource
of the form LISTA_ANTALLAKTIKWN?

= Turtle

George Papadopoulos said:
thx, for the help. The query I need to use is actually a bit more
sophisticated than the one I posted. Specifically the parameter (e.t.c.
2
in
the posted query) needs to be read from another table. Then I wan`t to
create the inner join of these two tables based on the read value.

George Papadopoulos

Ï "MacDermott said:
Well, you can do it by adding a reference to the DAO library.
From any code window, click Tools - References.
The DAO reference is there by default in Access 97, but not in later
versions.

But I have to wonder why you want to go programmatically creating a query
like that.
Why not just store it?
For one thing, that would keep you from having to delete it each time, after
creating it.

- Turtle


I am trying to access the Jet data engine using DAO. Specifically
I
have
attached an event handler to a button on a form. The code is shown
below
:

Private Sub List_spares_Click()
On Error GoTo Err_cmdGoHere_Click

Dim stDocName As String
Dim dbLib As DATABASE
Dim qdfSpares As QueryDef

' Set dbLib to the current database
Set dbLib = CurrentDb

' Create a query
Set qdfSpares = dbLib.CreateQueryDef("Spares",
"SELECT * FROM ANTALLAKTIKA WHERE [Kwdikos episkeyhs] = 2")


stDocName = "LISTA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]



Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click

End Sub

The code is supposed to execute a query and return a recordset
which
is
to
be displayed in another form. The code fails starting at the
statement
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top