Solved

Using callbacks from VBA/Access

Posted on 2004-10-25
571 Views
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.
0
Question by:Caltor
    4 Comments
     
    LVL 83
    Can you post the code you're currently using? Also, what exactly are you trying to accomplish with the callback?
    0
     
    LVL 3

    Author Comment

    by:Caltor
    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)
                
          EndProc

    EndDefine

    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()
                
                This.WriteLog(lcMessage)

          EndFunc

          Function Function1
          
                *-- Do some pre callback code...
                
                *-- Issue the callback
                This.oCallback.Event1()
                
                *-- Do some post callback code...
                
          EndFunc

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

          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)
                
          EndFunc
          
    EndDefine


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

          Function Event1()
          
    EndDefine

    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.

    0
     
    LVL 3

    Author Comment

    by:Caltor
    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.
    0
     

    Accepted Solution

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now