dbTalk Databases Forums  

Calling function with arguments from external VB application

comp.databases.ms-access comp.databases.ms-access


Discuss Calling function with arguments from external VB application in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Adam Kramer
 
Posts: n/a

Default Calling function with arguments from external VB application - 11-29-2004 , 07:06 PM






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

Reply With Quote
  #2  
Old   
Larry Linson
 
Posts: n/a

Default Re: Calling function with arguments from external VB application - 11-30-2004 , 11:05 PM






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" <adamjk (AT) gmail (DOT) com> wrote

Quote:
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



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.