VBScript read from MS Access

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

VBScript read from MS Access

Post by pgriffin » Tue May 10, 2005 6:35 pm

I see the examples of VBScript reading from an Access table, but I don't need to pass any parameter to look up. I need to read from Access, row by row, and place the values in 4 different MacroScheduler variables each time. every field into a variable and, eventually, every record of the database.



thanks for any response.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue May 10, 2005 6:42 pm

Consider exporting an ASCII text file from Access. Could actually execute that from Macro Scheduler once it is defined as a macro in Access.

Then continue to use Macro Scheduler to read the exported file, line by line in a loop, and assign the values to Macro Scheduler variables.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue May 10, 2005 7:19 pm

There's no reason why you can't do what you want - just split the code up and have a separate function that reads next record and returns the record as a delimited string. Here's an example:

VBSTART

Dim SQLString
Dim MyDB
Dim rsCustomers

Sub OpenRecordSet
set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "DSNCUS"
SQLString = "select * from Customers"
set rsCustomers = MyDB.Execute(SQLString)
rsCustomers.MoveFirst
End Sub

Sub CloseDB
MyDB.Close
End Sub

Function GetNextRecord
If Not rsCustomers.EOF then
GetNextRecord = rsCustomers.Fields("CustomerName") & ";" & _
rsCustomers.Fields("Address1") & ";" & _
rsCustomers.Fields("Address2")
rsCustomers.MoveNext
else
GetNextRecord = 0
end if
End Function

VBEND
VBRun>OpenRecordSet
Label>ReadLoop
VBEval>GetNextRecord,record
if>record=0,doneloop
Separate>record,;,fields
MessageModal>%fields_1%, %fields_2%, %fields_3%
Goto>ReadLoop
Label>doneloop
VBRun>CloseDB
MJT Net Support
[email protected]

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Tue May 10, 2005 7:52 pm

PERFECT! Can't thank you enough. All I had to do was change a few names, and voila!

once again, GREAT support.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts