Cannot connect VB script to Access .accdb

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
tennisdude
Posts: 7
Joined: Mon Jan 30, 2017 9:48 pm

Cannot connect VB script to Access .accdb

Post by tennisdude » Fri Mar 17, 2017 3:49 pm

Hi Imacros Forum,

First post here and I'm having an issue with the sample script connecting to a database I created. I'm using a windows 10 machine running 32bit OS
Database is Access 2007-2016 file format

The error I get when I click the script to run is
[img]
3333.PNG
3333.PNG (10.57 KiB) Viewed 3711 times
[/img]

Here's my code:

Code: Select all

Option Explicit

Dim objFileSystem, objOutputFile
Dim strOutputFile


' find current folder
Dim myname, mypath
myname = WScript.ScriptFullName
mypath = Left(myname, InstrRev(myname, "\"))

'Note for x64 users: You must start the VBS script in 32bit mode (C:\Windows\SysWOW64\wscript.exe) 
'for the Microsoft ODBC Driver to work
'Please see the note about VBS scripts on http://wiki.imacros.net/x64 for more details 

' access database
Dim db
set db = CreateObject("ADODB.Connection")
db.Open("Driver={Microsoft.ACE.OLEDB.12.0; (*.accdb)}; DBQ=" _
& "C:\Users\tomir\Documents" & "tennis_scraper_db.accdb")

Dim message
message = "This script demonstrates how to extract data from a web site and store this information directly in a database (MS ACCESS)."
message = message + " It uses the macro <wsh-extract-jobs.iim>." + vbCrLf + VbCrLf 
message = message + "Tip: This script has the same function as <extract-2-file.vbs> but stores the data in a database instead of a text file."

MsgBox(message)

Dim iim1, iret, iplay
set iim1= CreateObject ("imacros")
iret = iim1.iimOpen("")

if iret < 0 then
      MsgBox ("Error: " + CStr(iret))
      WScript.Quit(iret)
end if
      

Dim num, pos, str, rs, sql
For num = 1 To 3 
   str = cstr(num)  'Convert integer to string
   iret = iim1.iimDisplay("Listing No: " + str)

   pos = num '+ 4'start at 5: Offset for POS= statement
   str = cstr(pos)  'Convert integer to string
   iret = iim1.iimSet("myvar", str) 'Select a new link for each run

   iplay = iim1.iimPlay(mypath & "Macros\wsh-extract-jobs.iim")
   If iplay = 1  Then
	' use SQL to insert new data
	sql = "insert into tableJobListings (Salary, PositionType, RefCode) values ('" _
	& iim1.iimGetExtract(1) & "', '" & iim1.iimGetExtract(2) & "' ,  '" & iim1.iimGetExtract(3) & "')"

	' execute sql statement
	set rs = db.Execute(sql)
   End If

   If  iplay < 0 Then
      MsgBox "Error: " + iim1.iimGetErrorText()
   End If
Next

iret = iim1.iimClose

MsgBox "The data was stored in the <IIM-TEST-EXTRACT.MDB> database. The script is now completed."

WScript.Quit(iret)

Could the issue be with the way I set up the test database?

I'm a novice at access and VB so help would be greatly appreciated.
Thank you
tennisdude
Posts: 7
Joined: Mon Jan 30, 2017 9:48 pm

Re: Cannot connect VB script to Access .accdb

Post by tennisdude » Mon Mar 20, 2017 11:35 pm

Can anyone help or point me in the right direction?
Please?
Post Reply