Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Advanced
Aug 7, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Porting VB-Specific Objects to Access 8.0

Code portability is extremely important, especially now that VBA is available in so many products. Some problems might occur if you want to use VB4 or VB5 code in Access 8 without making any changes. If the code you are porting references some VB-specific object, object method, or property, Access complains when you compile the imported code. For instance, the "App" object exists in VB but not in Access. Therefore, this statement won't compile under Access:
Msgbox App.Title
To get around this problem, create a class in Access 8 to "replace" the VB4 object, method, or property not available in Access. In this case, create a clsVBShadow class in Access:
Option Compare Database
Option Explicit

Private strTitle As String
Private strEXEName As String
Private strMin As String

Private Sub Class_Initialize()
        strTitle = "Microsoft Access" 
        ' Or whatever you want to return.
        strEXEName = "?"
        strMin = "?"
End Sub

Public Property Get Title() As String
        Title = strTitle
End Property

Public Property Get EXEName() As String
        EXEName = strEXEName
End Property

' complete with more properties...
In any module in your Access 8 application, declare this global object:
Public App As New clsVBShadow
At this point, any code you import from VB4 that accesses the App object still works unchanged, and you can replace each method or property of that object with what you want.
Warren Roscoe
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date