473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calling function with arguments from external VB application

I am trying to call a module function in an Access db and then open a
report from a VB application. The problem I've found: I can't find a
good way to call a function that accepts arguments. I need to pass
arguments to set information that determines which information will
appear in the report.
Code Below:

MY argument accepting function:
Public Function SetCurrentIDs(PCaseID As String)
'Set the values if the pcase exists
If (DCount("PCaseID", "PCase", "PCaseID = '" & PCaseID & "'") = 1)
Then
MyCurrentPCaseID = PCaseID
MyCurrentPCaseIDAdden = DLookup("PCaseIDAdden", "PCase", _
"PCaseID = '" & PCaseID & "'")
MyCurrentPCaseIDAddenNo = DLookup("PCaseIDAddenNo", "PCase", _
"PCaseID = '" & PCaseID & "'")
MyCurrentStatus = DLookup("Status", "PCase", "PCaseID = '" & _
PCaseID & "'")
End If
End Function
MY VB code to call the above function and open a report:
Public Sub PrintAccessReport(dbName As String, _
rptname As String, _
preview As Boolean, _
eprsID As String)
Dim objAccess As Object
On Error GoTo PrintAccessReport_Err
Set objAccess = CreateObject("Access.Application")

With objAccess
.OpenCurrentDatabase filepath:=dbName
'.SetCurrentIDs eprsID
'BELOW ARE A FEW METHODS IVE UNSUCCESFULLY TRIED
.DoCmd.OpenModule "Globals", _
"SetCurrentIDs(""XXX"")"
.Run "SetCurrentIDs """ & eprsID & """"

If preview = True Then
.DoCmd.OpenReport reportname:=rptname, View:=acPreview
.Visible = True
.DoCmd.Maximize
.DoCmd.Maximize
.Globals.SetCurrentIDs
Else
.DoCmd.OpenReport reportname:=rptname, View:=acNormal
DoEvents
End If
End With

Set objAccess = Nothing
PrintAccessReport_Exit:
Exit Sub
PrintAccessReport_Err:
'LogCriticalError "PrintAccessReport"
Debug.Print Err.Number & " - " & Err.Description
Resume PrintAccessReport_Exit
End Sub

When I do try the Run or DoCmd functions to call my function I usually
get a "2517 - XXX can't find the procedure 'XXX.'" error.

Any Ideas? Any help is greatly appreciated.

Thanks for reading,
Adam
Nov 13 '05 #1
1 3387
Look at controlling Access via COM Automation. It is a
COM-Autpomation-enabled product. That is far too comprehensive a subject to
address in a newsgroup response.

You will have to learn the Access object model, but the VBA itself will be
familiar, because the VBA.DLL is the core language of classic VB, too.

Larry Linson
Microsoft Access MVP
"Adam Kramer" <ad****@gmail.com> wrote in message
news:d9**************************@posting.google.c om...
I am trying to call a module function in an Access db and then open a
report from a VB application. The problem I've found: I can't find a
good way to call a function that accepts arguments. I need to pass
arguments to set information that determines which information will
appear in the report.
Code Below:

MY argument accepting function:
Public Function SetCurrentIDs(PCaseID As String)
'Set the values if the pcase exists
If (DCount("PCaseID", "PCase", "PCaseID = '" & PCaseID & "'") = 1)
Then
MyCurrentPCaseID = PCaseID
MyCurrentPCaseIDAdden = DLookup("PCaseIDAdden", "PCase", _
"PCaseID = '" & PCaseID & "'")
MyCurrentPCaseIDAddenNo = DLookup("PCaseIDAddenNo", "PCase", _
"PCaseID = '" & PCaseID & "'")
MyCurrentStatus = DLookup("Status", "PCase", "PCaseID = '" & _
PCaseID & "'")
End If
End Function
MY VB code to call the above function and open a report:
Public Sub PrintAccessReport(dbName As String, _
rptname As String, _
preview As Boolean, _
eprsID As String)
Dim objAccess As Object
On Error GoTo PrintAccessReport_Err
Set objAccess = CreateObject("Access.Application")

With objAccess
.OpenCurrentDatabase filepath:=dbName
'.SetCurrentIDs eprsID
'BELOW ARE A FEW METHODS IVE UNSUCCESFULLY TRIED
.DoCmd.OpenModule "Globals", _
"SetCurrentIDs(""XXX"")"
.Run "SetCurrentIDs """ & eprsID & """"

If preview = True Then
.DoCmd.OpenReport reportname:=rptname, View:=acPreview
.Visible = True
.DoCmd.Maximize
.DoCmd.Maximize
.Globals.SetCurrentIDs
Else
.DoCmd.OpenReport reportname:=rptname, View:=acNormal
DoEvents
End If
End With

Set objAccess = Nothing
PrintAccessReport_Exit:
Exit Sub
PrintAccessReport_Err:
'LogCriticalError "PrintAccessReport"
Debug.Print Err.Number & " - " & Err.Description
Resume PrintAccessReport_Exit
End Sub

When I do try the Run or DoCmd functions to call my function I usually
get a "2517 - XXX can't find the procedure 'XXX.'" error.

Any Ideas? Any help is greatly appreciated.

Thanks for reading,
Adam

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
3
by: Glenn C. Rhoads | last post by:
I'm having a problem calling a C function from a publicly available library file. To get the code to compile, I had to declare the function as an external C function as follows. extern "C"...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
4
by: Sivakumar Shanmugam | last post by:
Group.. We are running on db2 UDF V8 on Sun solaris platform. I created an UDF which calles a C-routine(SQL_API_FN). This C-routine in turn calls an external C-function. The C-function is provided...
17
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work....
13
by: leaf | last post by:
How can i call arbirary functions at runtime, that with arbirary parameters and types? Can BOOST.Bind do that?
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.