Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From Attachmate to SQL

Status
Not open for further replies.

DemBones79

Programmer
Jun 12, 2008
7
US
I know that VBScript can communicate directly to a database through ADO connections and SQL. Is there anyway to get the VB-like macro language of Attachmate to do the same?

Alternatively, is there a way to pass variables from the macro script to a .VBS file if you can't connect to a database directly?
 
DemBones79,

I often use an Access database to hold information, and add to it from an Extra macro:

Code:
dim cnn as object
set cnn = createobject("ADODB.Connection")
    
dim rst as object
set rst = createobject("ADODB.Recordset")
    
MyConn = "C:\Example.mdb"

    
' open the connection
With cnn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Open MyConn
End With
    
rst.CursorLocation = 2
    
' open the table
rst.Open Source:="tblExample", _
ActiveConnection:=cnn, _
CursorType:=2, _
LockType:=3, _
Options:=2
    
' Add a record
rst.AddNew

' work with rst here

' Update the record
rst.Update

' close the recordset and connection
rst.Close
cnn.Close

I don't know if this is the most elegant way to do the job, but it works for me. Note that you could set your source to be an SQL query rather than a table, and go from there. I'm assuming from your post that you know what you're doing once you get the connection set up.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top