Discussion:
Read a Query in Access vb-code
(too old to reply)
Gewle
2010-05-26 00:52:23 UTC
Permalink
Hi, I have made a database with an interface both created in Access 2007.

I have created a "Select Query" in Access.
When I click a button, I would like to "retrieve" information from "that
query" (through vb code).

Please help..
gewle
2010-05-26 00:56:04 UTC
Permalink
Forgot to say that I'm using ".mdb", not ".accdb".
gewle via VBMonster.com
2010-05-26 13:12:39 UTC
Permalink
ok.. Thanks to all.
--
Message posted via http://www.vbmonster.com
Michael Cole
2010-05-26 02:12:50 UTC
Permalink
Post by Gewle
Hi, I have made a database with an interface both created in Access 2007.
I have created a "Select Query" in Access.
When I click a button, I would like to "retrieve" information from "that
query" (through vb code).
Please help..
Probably better to ask in an Access group, as this is specific to
Visual Basic stand-alone product, not VBA, which Access uses.

Try microsoft.public.access
--
Michael Cole
ralph
2010-05-26 11:44:37 UTC
Permalink
Post by Gewle
Hi, I have made a database with an interface both created in Access 2007.
I have created a "Select Query" in Access.
When I click a button, I would like to "retrieve" information from "that
query" (through vb code).
Please help..
You can use DAO in VB to access a Query.

Some good clues:
http://allenbrowne.com/func-DAO.html

You can also use ADO:
Something like this ...
' Warning air code
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command

cn.ConnectionString = "your connection string"
cn.Open

cmd.CommandType = adCmdStoredProc
cmd.CmdText = "your query name"

' assume some string parameter for your query
' if no parameters then just skip
cmd.Parameters.Append cmd.CreateParameter("ParamName", adChar,
adParamInput, 50, "new string value" )

cmd.Execute
' End example

You can find additional examples on the web.
Note: DAO is the preferred method for a local Mdb database.

-ralph
ralph
2010-05-26 11:59:30 UTC
Permalink
On Wed, 26 May 2010 06:44:37 -0500, ralph <***@yahoo.net>
wrote:

Left out catching a return if any ...

Set rs = New ADODB.Recordset
rs.Source = "Your Query Name"
rs.Open , cn, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc

- or -

With cmd
.Connection = cn
.CommandType = adCmdStoredProc
.CommandText = "Your Query Name"
.Parameters.Append .CreateParameter( _
"Some String Param", adChar, adParamInput, 9, "String Value")
End With

Set rs = New ADODB.Recordset
rs.Open cmd, , adOpenKeyset, adLockOptimistic

-ralph
Loading...