Using Third Party DLL with Access VBA

Hi,

I'm starting a project to integrate a third party add-in from SagePay to our in-house Access database and unsure on some of the basics. I've completed the following steps but not clear on where the initial problem lies. Any assistance appreciated..

1. Discovered that I need a type library (tlb file) for the dll so I generated file using regasm (have .net framework 4.5 installed which is a listed minimum requirement)

(regasm.exe in c:\windows\microsoft.net\framework\v4.0.30319 = v4.5 folder after upgrade by all accounts)
regasm c:\sagepay\guardian\bin\Integral.Library.GuardianClient.dll /tlb

Open in new window


2. Added a reference to the add-in to vba project
VBA reference to SagePay dll
3. Declared function call for the add-in using documentation:

Public Declare Function Process Lib "c:\sagepay\guardian\bin" ( _
        ByVal transactionType As TRANSACTIONHOOK_TRANSACTIONTYPE, _
        ByVal transactionAmount As Integer, _
        ByRef tillInfo As TillInformation, _
        ByRef transInfo As TransactionInfo) _
As Boolean

Open in new window


4. This is where my knowledge gets a bit sketchy; I assumed the add-in would include the tillinformation type definition which I checked in the object browser but this is not the case as it shows no members?

VBA object view of TillInformation class
Hence, declared a VBA type as shown to match the documentation although documentation does not specify actual data types. I've tried varying strings / integers for some of the type declarations with no effect.
Public Type TillInformation
    merchantname As String
    address1 As String
    address2 As String
    address3 As String
    address4 As String
    phonenumber As String
    sitenumber As String
    tillnumber As String
    receiptnumber As String
    operatorid As String
End Type

Open in new window


5. Now when I try to call the function fro a test form, I get a type mismatch with 'tillinformation' parameter so it’s obviously not happy with the declaration..

Runtime / compile error with Process function
I don't know if the issue is with the add-in registration or the way I'm trying to declare the necessary types etc. so desperately in need of some guidance please! Thanks
nigelr99Asked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The Imports statement in .NET would indicate the need for you to have a reference in VBA.

I can see that TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE.INT_TT_SALE=0
Try setting the line value to 0:

TransactionType = 0
0
 
Máté FarkasDatabase Developer and AdministratorCommented:
Hi,
There are 2 types of DLL-s in this case:
1. C++ function library: these are the traditional windows DLL libraries. You cannot and don't need to register them just put into the same folder as the access database file or Windows\system32 folder. Then you can call functions from this library after you define them in VBA with Declare ...
2. OCX, OLE type library: you have to register them with regsvr32 into windows and/or add them to VBA project. This way you don't have to Declare any function using the library. Library becomes the part of VBA classes and you can create a new instance of any object with New.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Can you point us to the documentation you mention?

SagePay is an internet-based service. In general, you interact with those from the desktop using a web service via SOAP, or communicate directly through URLs (REST) using methods like GET, PUT, etc
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
nigelr99Author Commented:
Documentation attached. It's software called Guardian which handles transactions for integrated solutions. It's not platform specific by any means but ..
 SagePay-Guardian-Setup-Guide.pdf
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Try this:

Dim TillInformation As New TillInformation
0
 
nigelr99Author Commented:
OK - tried that and now get a file location error.. not sure what file it could be referring to other than the dll which is in the c:\sagepay folder
File not found error
0
 
nigelr99Author Commented:
'Fixed' that error after some research by adding /codebase to regasm command. However, I now have 'object required'
Object Required Error
0
 
nigelr99Author Commented:
..using the object viewer, I can see that TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE.INT_TT_SALE=0
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
If your setting a reference, you don't need the declare's and they should be removed.   Instead, you instantiate an object and then work with that.   Your file not found may be coming out of that.

 Also be aware that Access (VBA) lacks full support for the IDispatch interface, so you may find it simply doesn't work.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<'object required'>>

 You didn't set the Transaction object.  Should be:

 Dim transaction As New TransactionHook
 Dim transactionType As TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE

Jim.
0
 
nigelr99Author Commented:
Apologies, I really need to spend some time getting to grips with the ins and outs of this. I now have a type mismatch?
Type mismatch error
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
and BTW no points for me please.   I didn't mean to butt in....just thought it was an interesting question.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You may need this:

Public Enum TRANSACTIONHOOK_TRANSACTIONTYPE
INT_TT_SALE = 0
INT_TT_REFUND
INT_TT_PREAUTH
INT_TT_FINALAUTH
INT_TT_PREAUTHPARTIAL
INT_TT_FINALAUTHADVISE
End Enum

  I'm looking at the code example on page 20 of the docs and it shows:

Imports Integral.Library.GuardianClient

 which you don't have in VBA.  Problem is, it's not showing all the values, which seems to be a mistake to me, but then this is .Net code in the examples.  Scott may have more input on that.  I don't do much .Net.

Jim.
0
 
nigelr99Author Commented:
OK - I set TransactionType to 0 and also declared transactionType As Integer to save messing about :-)

It appears to run although I obviously have a lot of testing to do! Thanks very much for your help. I guess I should close this question and raise any more as required?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.