Using callbacks from VBA/Access

Posted on 2004-10-25
Medium Priority
Last Modified: 2012-08-13
I am following the instructions in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfoxgen7/html/vfpandcom.asp
for using callbacks. It works absolutely fine from VFP8 but I need to use this method from Microsoft Access (vba). When I try the same thing from Access I get the following error message. ".SETCALLBACK: callback must be object." It would appear that the parameter being passed instead of the callback object is an empty character string.
Please help I really need to get this working from Access.
Question by:Caltor
  • 2
LVL 85
ID: 12402574
Can you post the code you're currently using? Also, what exactly are you trying to accomplish with the callback?

Author Comment

ID: 12410447
Code is posted below. The idea of the callback is to allow me a core product COM/DLL and then create extensions using an additional COM/DLL. The two are then bound together using the callbacks.
The entire project is huge and very specific so I have created a sample of the problem.
You can download the entire thing from http://www.helixnet.co.uk/callback.zip
You will need to register proj1.dll and proj2.sll using regsvr32
eg regsvr32 proj1.dll
regsvr32 proj2.dll
After you have done this you can look at the db1.mdb that has a demo of the problem.
The problems are logged in c:\app.log

Alternatively if you like typing you can use all the code below....

Access Code attached to a command button
Option Compare Database

Private Sub Command1_Click()
    Dim objCallback As Object
    Dim objMain As Object
    Set objMain = CreateObject("proj1.class1")
    Set objCallback = CreateObject("proj2.eventhandler")
    objMain.SetCallback (objCallback)
    MsgBox ("Program completed!")
End Sub

Create a program called program2 in Visual Foxpro 8 and paste the following code
Define Class EventHandler As Session OlePublic

      Implements Iapplicationevents In "proj1.ApplicationEvents"

      Procedure Iapplicationevents_Event1() AS VARIANT
            *-- Perform the callback code
            StrToFile("Dummy File","c:\dummy.txt",0)


Add this program to a project called proj2 and build into a COM/DLL

Create a program called program1 in vfp8 and paste the following code:
Define Class Class1 As Session OLEPublic

      oCallback = .Null.
      Function Error(tnError, tcMethod, tnLine)
            Local lcMessage As String, lnObjectName As String
            lcObjectName = This.Name

            lcMessage = "ERROR: "+lcObjectName+"."+tcMethod+" "+"Line: "+AllTrim(Str(tnLine))+" "+Message()


      Function Function1
            *-- Do some pre callback code...
            *-- Issue the callback
            *-- Do some post callback code...

      Function Init
            *-- Initialise Callback Object
            This.WriteLog("Initialise callback object")
            This.WriteLog("Callback object has been initialised")
      Function SetCallback(toCallback As Object)
            Local lcType As Character
            If IsNull(toCallback)
                  *-- dummy instance that does nothing
                  This.oCallback = NewObject("ApplicationEvents")
                  *-- Check callback variable is an object
                  lcType = Vartype(toCallBack)
              If lcType != 'O'
                     This.WriteLog(PROGRAM()+": callback must be object. Parameter passed is "+lcType)
                  This.oCallback = GetInterface(toCallback, "IApplicationEvents", "proj1.class1")

      Function WriteLog(tcString)
            *-- Write expression to default log file
            *-- Prefix with date and time
            *-- Suffix with file name
            *-- Always append to file
            StrToFile(Dtoc(Date())+" "+Time()+" - "+tcString+Chr(13)+Chr(10),"c:\app.log",1)

Define Class ApplicationEvents As Session OLEPublic
*-- Template for Callback Interface --*

      Function Event1()

Add this program to a project called proj1 and build into a COM/DLL

You will then be able to try the access sample above.


Author Comment

ID: 12546051
I have solved this problem myself with the help of Microsoft.
I changed the object types in Access to type Variant instead of type Object.

Accepted Solution

ee_ai_construct earned 0 total points
ID: 12578943
Question answered by asker or dialog valuable.
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question