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++.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Cannot connect VB script to Access .accdb

by tennisdude on Fri Mar 17, 2017 8:49 am

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 680 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 2:48 pm

Re: Cannot connect VB script to Access .accdb

by tennisdude on Mon Mar 20, 2017 4:35 pm

Can anyone help or point me in the right direction?
Please?
tennisdude
 
Posts: 7
Joined: Mon Jan 30, 2017 2:48 pm


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 4 guests

-->