Call access modulo /macro from vb6

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Call access modulo /macro from vb6

Post by sal21 »

I just have a module in access data base possible to call it via vb 6.0?

Note:
i just have a ADO jet connection actine in vb 6.0 project tath point to a access database where is the module.

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

You'd have to run Access from your VB6 application. It would be easier to copy the code into your application.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Re: Call access modulo /macro from vb6

Post by sal21 »

No.
I Need to run via vb6.
Tks
An example palese.

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

Code: Select all

    Dim objAccess As Object
    Set objAccess = CreateObject(Class:="Access.Application")
    objAccess.OpenCurrentDatabase "C:\MyFolder\MyDatabase.mdb"
    objAccess.Run "MyProcedure"
    objAccess.Quit
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Re: Call access modulo /macro from vb6

Post by sal21 »

HansV wrote:
05 Nov 2024, 23:16

Code: Select all

    Dim objAccess As Object
    Set objAccess = CreateObject(Class:="Access.Application")
    objAccess.OpenCurrentDatabase "C:\MyFolder\MyDatabase.mdb"
    objAccess.Run "MyProcedure"
    objAccess.Quit
Tks Bro.
Dubt...
In my vb6 project have a public variabile i can pass It in the access modulo?

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

Does the procedure (Sub) in the Access database have an argument? For example

Code: Select all

Sub MyProcedure(Regione As String)
or

Code: Select all

Sub MyProcedure(Anno As Long)
If so, you can use

Code: Select all

    objAccess.Run "MyProcedure", MyVar
where MyVar is the name of your public variable.

Otherwise: no.
Best wishes,
Hans

User avatar
SpeakEasy
5StarLounger
Posts: 753
Joined: 27 Jun 2021, 10:46

Re: Call access modulo /macro from vb6

Post by SpeakEasy »

>I Need to run via vb6

Is this because you (or your users) won't have Access? In which case Hans' solution won't work because it essentially is running Access (because, as he says, you need to do that to meet your requirement)

Having an 'ADO jet connection' only gives you access to the Jet SQL database, not to the entire Access database management system

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Re: Call access modulo /macro from vb6

Post by sal21 »

sal21 wrote:
06 Nov 2024, 08:09
HansV wrote:
05 Nov 2024, 23:16

Code: Select all

    Dim objAccess As Object
    Set objAccess = CreateObject(Class:="Access.Application")
    objAccess.OpenCurrentDatabase "C:\MyFolder\MyDatabase.mdb"
    objAccess.Run "MyProcedure"
    objAccess.Quit
Tks Bro.
Dubt...
In my vb6 project have a public variabile i can pass It in the access modulo?
I have the module in image, and the procedure is named sub WebAutomationSelenium ()

is correct, in my tyest code:

Option Explicit
Private Sub Form_Load()

Dim objAccess As Object
Set objAccess = CreateObject(Class:="Access.Application")
objAccess.OpenCurrentDatabase "C:\Lavori_Vb6\MAPPA_ITALIA\DATABASE\COMUNI.mdb"
objAccess.Run "CHROME_TEST"
objAccess.Quit

End Sub
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

You have to use the name of the procedure, not the name of the module.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Re: Call access modulo /macro from vb6

Post by sal21 »

HansV wrote:
06 Nov 2024, 09:25
You have to use the name of the procedure, not the name of the module.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

Are you sure that you spelled the name correctly? And that the procedure is not Private?

Similar code works correctly for me!
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

Re: Call access modulo /macro from vb6

Post by sal21 »

HansV wrote:
06 Nov 2024, 10:11
On which line does the error occur?
objAccess.Run "WebAutomationSeleniumo"

Code: Select all

Option Compare Database
Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub WebAutomationSelenium()
    
    Dim bot As Object, VALORE As String, ISTAT As String
    Dim Table As Object, Rows As Object, Row As Object, Cells As Object, Cell As Object
    Dim I As Integer, J As Integer
    
    Set bot = CreateObject("Selenium.WebDriver")
    bot.Start "Chrome"
    bot.Get "https://demo.istat.it/app/?i=D7B&l=it&a=2024"
    bot.Window.Maximize
    Sleep 2000
    
    bot.FindElementById("tab-1").Click
    Sleep 2000
    
    bot.FindElementById("provincerb-1").Click
    Sleep 2000
    
    bot.ExecuteScript "document.getElementById('province-1').removeAttribute('disabled');"
    Sleep 2000
    
    Dim provinceDropdown As Object
    Set provinceDropdown = bot.FindElementById("province-1")
    For I = 1 To provinceDropdown.FindElementsByTag("option").Count - 1
        If provinceDropdown.FindElementsByTag("option")(I).Text = "Como" Then
            provinceDropdown.FindElementsByTag("option")(I).Click
            Exit For
        End If
    Next
    
    Sleep 1000
    
    Dim monthDropdown As Object
    Set monthDropdown = bot.FindElementById("mese")
    For I = 1 To monthDropdown.FindElementsByTag("option").Count '- 1
        'Debug.Print monthDropdown.FindElementsByTag("option")(I).Text
        If monthDropdown.FindElementsByTag("option")(I).Text = "Luglio" Then
            'Debug.Print monthDropdown.FindElementsByTag("option")(I).Text
            monthDropdown.FindElementsByTag("option")(I).Click
            Exit For
        End If
    Next
    
    Sleep 1000
    
    bot.FindElementById("btnricerca-1").Click
    Sleep 1000
    
    Set Table = bot.FindElementById("tavola-form-1")
    Set Rows = Table.FindElementsByTag("tr")
    
    For I = 1 To Rows.Count - 1
        Set Row = Rows.Item(I)
        Set Cells = Row.FindElementsByTag("td")
        For J = 1 To Cells.Count - 1
        
            Set Cell = Cells.Item(J)
            
            VALORE = "Row " & I & ", Column " & J & ": " & Cell.Text
            
            ISTAT = Cell.Text
            
            Debug.Print VALORE
            
        Next J
    Next I
    
    bot.Quit
    Set bot = Nothing
    
End Sub



User avatar
SpeakEasy
5StarLounger
Posts: 753
Joined: 27 Jun 2021, 10:46

Re: Call access modulo /macro from vb6

Post by SpeakEasy »

As Hans says "And that the procedure is not Private?"

Private Sub WebAutomationSelenium()

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Call access modulo /macro from vb6

Post by HansV »

Change Private Sub to Public Sub.

Alternatively, try

objAccess.Run "CHROME_TEST.WebAutomationSelenium"
Best wishes,
Hans