By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,932 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,932 IT Pros & Developers. It's quick & easy.

Calling function with arguments from external VB application

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.