Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using callbacks from VBA/Access

Posted on 2004-10-25
5
Medium Priority
?
597 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
Comment
Question by:Caltor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 85
ID: 12402574
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
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)
            
      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
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.
0
 

Accepted Solution

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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