Rob4077
asked on
Does a VBScript editing an Access database run with 2007 Runtime?
Does anyone know if the following vbScript code will work on a PC that only has MS Access 2007 runtime, not the full MS Access?
Dim appAccess
Dim strDBNameAndPath
Dim dbe
Dim dbs
Dim strSQL
Set appAccess = _
WScript.CreateObject("Acce ss.Applica tion")
Set fso = _
WScript.CreateObject("Scri pting.File SystemObje ct")
strDBNameAndPath= "C:myFolder\myApp.mdb"
On Error Resume Next
Set fil = fso.GetFile(strDBNameAndPa th)
If fil Is Nothing Then
strPrompt = "Can't find " & strDBNameAndPath& _
"; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
Else
Set dbe = appAccess.DBEngine
Set dbs = dbe.OpenDatabase(strDBName AndPath)
Set rst = dbs.OpenRecordset("tblMyTa ble")
Do Until rst.EOF
rst.edit
rst.[Description] = rst.[Description] & "."
rst.update
rst.MoveNext
Loop
rst.Close
End If
Set rst = Nothing
Set appAccess = Nothing
Dim appAccess
Dim strDBNameAndPath
Dim dbe
Dim dbs
Dim strSQL
Set appAccess = _
WScript.CreateObject("Acce
Set fso = _
WScript.CreateObject("Scri
strDBNameAndPath= "C:myFolder\myApp.mdb"
On Error Resume Next
Set fil = fso.GetFile(strDBNameAndPa
If fil Is Nothing Then
strPrompt = "Can't find " & strDBNameAndPath& _
"; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
Else
Set dbe = appAccess.DBEngine
Set dbs = dbe.OpenDatabase(strDBName
Set rst = dbs.OpenRecordset("tblMyTa
Do Until rst.EOF
rst.edit
rst.[Description] = rst.[Description] & "."
rst.update
rst.MoveNext
Loop
rst.Close
End If
Set rst = Nothing
Set appAccess = Nothing
No it will not run on a machine without access installed since you are using the access object in your code ( Set appAccess = WScript.CreateObject("Acce ss.Applica tion"). That creation step requires Access. You can re-write this using ADO to get access to the database. Let me know if you need help with getting it into new code. If I get a chance I may just do it anyway.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Bear, That appears to be just what I need. You said << It should work on a machine without access installed >>. You mean as long as the runtime version is installed or will it work even without runtime installed? Is it going to foul up registries if there machine has both runtime 2007 and another version of MS Access installed? It looks to me like this will be a perfect solution for me if it works that way.
The could is not fully tested and that is what I mean by should. It uses the Jet driver which will be on many machines by default, but you may need to install the run time on some. You will need to just test just to verify.
ASKER
That is fantastic. I will test and refine it, no problems. I only asked in case you knew. Appreciate your kind assistance.
Rob
Rob