pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedcalling a pg-function from vba (Access 2002)
3+ messages / 3 participants
[nested] [flat]
* calling a pg-function from vba (Access 2002)
@ 2003-11-12 11:25 Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>
0 siblings, 1 reply; 3+ messages in thread
From: Wilhelm Graiss @ 2003-11-12 11:25 UTC (permalink / raw)
To: pgsql-odbc
Hello,
We have a question concerning the vba-code which is posted on
http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-accessvba:
We have a function in postgres (Version 7.3.2) and would like to call it
from vba on Access 2002 (a.k.a XP) with different parameters each time.
We searched the Net and played with the code, but with no success. The
connection to postgres works, the problem is how to trigger the "select
myfunction(param1, param2, param3)" - thing from vba...
The main problem is, I think, that it is our first try in vba ;-) The other
time we spend the time with php...
Would be great if somebody could help us, and thanks in advance!
Greetings from Austria!
Albin Blaschka, Wilhelm Graiss
--
===================================================
Wilhelm Graiss, Dipl. Ing.
Federal Reasearch Agency for Alpine Agriculture
8952 Irding, Styria
Austria, Europe
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: calling a pg-function from vba (Access 2002)
@ 2003-11-12 23:57 Jeff Eckermann <jeff_eckermann@yahoo.com>
parent: Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Eckermann @ 2003-11-12 23:57 UTC (permalink / raw)
To: Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>; pgsql-odbc
--- Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>
wrote:
> Hello,
>
> We have a question concerning the vba-code which is
> posted on
>
http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-accessvba:
>
> We have a function in postgres (Version 7.3.2) and
> would like to call it
> from vba on Access 2002 (a.k.a XP) with different
> parameters each time.
>
> We searched the Net and played with the code, but
> with no success. The
> connection to postgres works, the problem is how to
> trigger the "select
> myfunction(param1, param2, param3)" - thing from
> vba...
You need to do a passthrough query. Just supplying a
connection string for your querydef will cause the SQL
to be sent directly to the server, instead of to Jet.
So all you need then is to capture the parameters
according to your preference, construct your query
string and use it to set your sql property.
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: calling a pg-function from vba (Access 2002)
@ 2003-11-13 07:35 Philippe Lang <philippe.lang@attiksystem.ch>
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Lang @ 2003-11-13 07:35 UTC (permalink / raw)
To: Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>; pgsql-odbc
Hello,
Here is a small example:
Two routines; the first stores the pass-through query in order to use is from a form or a report, and a second for internal use.
I hope this helps.
Note: global_dsn_name() supplies the DSN name of your ODBC connection.
-----------------------------------------
Sub query_store(query As String, p As String)
On Error GoTo query_storeError
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Set MyDatabase = CurrentDb()
If (QueryExists(query)) Then MyDatabase.QueryDefs.Delete query
Set MyQueryDef = MyDatabase.CreateQueryDef(query)
MyQueryDef.Connect = "ODBC;DSN=" & global_dsn_name() & ";"
MyQueryDef.SQL = "SELECT * FROM public." & """" & query & """" & "('" & p & "');"
MyQueryDef.ReturnsRecords = True
MyQueryDef.Close
Set MyQueryDef = Nothing
MyDatabase.Close
Set MyDatabase = Nothing
query_storeExit:
Exit Sub
query_storeError:
HandleErrors "Error in query_store."
Resume query_storeExit
End Sub
-----------------------------------------
Sub query_run(query As String, p As String)
On Error GoTo query_runError
Dim MyWorkspace As DAO.Workspace
Dim MyConnection As DAO.Connection
Dim MyRecordset As DAO.Recordset
Dim MySQLString As String
Dim MyODBCConnectString As String
Set MyWorkspace = CreateWorkspace("ODBCWorkspace", "", "", dbUseODBC)
MyODBCConnectString = "ODBC;DSN=" & global_dsn_name() & ";"
Set MyConnection = MyWorkspace.OpenConnection("Connection1", dbDriverNoPrompt, , MyODBCConnectString)
MySQLString = "SELECT * FROM public." & """" & query & """" & "('" & p & "');"
Set MyRecordset = MyConnection.OpenRecordset(MySQLString, dbOpenDynamic)
With MyRecordset
Do While Not .EOF
Debug.Print _
MyRecordset("col1") & " / " & _
MyRecordset("col2") & " / " & _
MyRecordset("col3") & " / " & _
MyRecordset("col4") & " / " & _
MyRecordset("col5")
.MoveNext
Loop
End With
MyRecordset.Close
Set MyRecordset = Nothing
MyConnection.Close
Set MyConnection = Nothing
MyWorkspace.Close
Set MyWorkspace = Nothing
query_runExit:
Exit Sub
query_runError:
HandleErrors "Error in query_run."
Resume query_runExit
End Sub
-----------------------------------------
-----Message d'origine-----
De : Wilhelm Graiss [mailto:Wilhelm.Graiss@bal.bmlfuw.gv.at]
Envoyé : mercredi, 12. novembre 2003 12:26
À : 'pgsql-odbc@postgresql.org'
Objet : [ODBC] calling a pg-function from vba (Access 2002)
Hello,
We have a question concerning the vba-code which is posted on
http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-accessvba:
We have a function in postgres (Version 7.3.2) and would like to call it
from vba on Access 2002 (a.k.a XP) with different parameters each time.
We searched the Net and played with the code, but with no success. The
connection to postgres works, the problem is how to trigger the "select
myfunction(param1, param2, param3)" - thing from vba...
The main problem is, I think, that it is our first try in vba ;-) The other
time we spend the time with php...
Would be great if somebody could help us, and thanks in advance!
Greetings from Austria!
Albin Blaschka, Wilhelm Graiss
--
===================================================
Wilhelm Graiss, Dipl. Ing.
Federal Reasearch Agency for Alpine Agriculture
8952 Irding, Styria
Austria, Europe
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-11-13 07:35 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-12 11:25 calling a pg-function from vba (Access 2002) Wilhelm Graiss <Wilhelm.Graiss@bal.bmlfuw.gv.at>
2003-11-12 23:57 ` Jeff Eckermann <jeff_eckermann@yahoo.com>
2003-11-13 07:35 Re: calling a pg-function from vba (Access 2002) Philippe Lang <philippe.lang@attiksystem.ch>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox