user10035655
user10035655

Reputation:

how to call dll from ms access?

I'm calling a JordanIdCardReader.dll in C# and everything sounds good, below is the code in C#.

How can I call this dll file in VBA MS Access?

I know I have to use the Declare keyword as the following

Public Declare Function test1 Lib "C:\Windows\System32\JordanIdCardReader.dll" (ByRef card_no As String) As String

but I don't know how to declare the parameters to it? any help?

CardReader reader = new CardReader();

CardInfo cardInfo = reader.Read(Card_no.Text);

txtFirstName.Text = cardInfo.FirstNameEn;
txtMiddleName.Text = cardInfo.MiddleNameEn;
txtFamilyName.Text = cardInfo.LastNameEn;
txtNameAR.Text = cardInfo.FullNameAr;
txtPhoneNum.Text = cardInfo.MobileNumber;
txtMobNum.Text = cardInfo.PhoneNumber;
txtBirthDate.Text = cardInfo.DateOfBirth;
txtAddress1.Text = cardInfo.Address1;
txtAddress2.Text = cardInfo.Address2;
txtCity.Text = cardInfo.City;
txtID.Text = cardInfo.IdNumber;
txtExpiryDate.Text = cardInfo.ExpiryDate;
txtNationalID.Text = cardInfo.NationalId;
txtIssuePlace.Text = cardInfo.IssuePlace;
txtGender.Text = cardInfo.Gender;
txtMotherName.Text = cardInfo.MotherName;
txtAddress.Text = cardInfo.Address;
txtCivilNum.Text = cardInfo.CivilNumber;
txtCivilOffic.Text = cardInfo.CivilOffice;

Upvotes: 0

Views: 2294

Answers (1)

Albert D. Kallal
Albert D. Kallal

Reputation: 49039

If that .dll is managed .net code, then you can't use the .dll as a non managed .dll from Access by using public decleare + path to the .dll.

That type of .dll reference in Access only allows use of a win32 bit .dll, and not a managed .dll. If you are consuming that .dll from .net as a simple assembly referance, then that .dll is a .net ONLY .dll and can ONLY be used from .net.

However, what you can do is create a class in .net, reference that assembly, and then compile the .net class as a COM object. That COM object can then be freely used by Access. You have to "register" that COM object, and then from VBA go tools->references and add that reference (or use late binding).

So Access can consume two types of external libraries. COM objects is like when you consume word or other 3rd party .dll's from Access. This in effect is based on the ActiveX or what we often call "COM" objects. So, you can create a .net class,and expose that .net .dll as a COM object. it actually only a few extra lines of code to do this.

Using the VBA declare + path to a .dll only works for standard windows c++ (and possible VB6) created .dlls. As such these are just pure un-managed (non .net) code libraries that you can call + use from Access. This type of .dll is not to be confused with the COM type external libraries (which as noted means a VBA reference is required from VBA tool->references).

If you have a reference or link to the .net example, then I will post a example wee bit of code in .net that would allow you to use that .dll from Access.

Upvotes: 3

Related Questions