Hi all
This might be a contender for the VBScript forum, but it's Access related so thought i'd try here!
One of my colleagues has been kind enough to pass me the below code, which stops Access 2003 JET4 SP8 warning messages popping up when launching an mdb. (fantastic piece of script!)
It works fine if i hard code the path to the file, but I need to constuct the full path using the environment variable UserName, as per in the example below.
But when i do this, i get the error "Expected literal constant". I THINK i know this is an issue with the unknown length of the string, but am lost from there on!
Be very grateful for any assistance
Many thanks
Adam
This might be a contender for the VBScript forum, but it's Access related so thought i'd try here!
One of my colleagues has been kind enough to pass me the below code, which stops Access 2003 JET4 SP8 warning messages popping up when launching an mdb. (fantastic piece of script!)
It works fine if i hard code the path to the file, but I need to constuct the full path using the environment variable UserName, as per in the example below.
But when i do this, i get the error "Expected literal constant". I THINK i know this is an issue with the unknown length of the string, but am lost from there on!
Be very grateful for any assistance
Many thanks
Adam
Code:
Dim AcApp
Dim oShell
Dim strUser
Dim strPath
On Error Resume Next
Set oShell = Wscript.CreateObject("Wscript.Shell")
strUser = oShell.ExpandEnvironmentStrings("%UserName%")
strPath = "C:\Documents and Settings\" & strUser & "\Desktop\PET.mdb"
Const cDatabaseToOpen = strpath
Set AcApp = CreateObject("Access.Application")
If Val(AcApp.Version) >= 11 Then
AcApp.AutomationSecurity = 1 ' msoAutomationSecurityLow
End If
AcApp.Visible = True
AcApp.OpenCurrentDatabase cDatabaseToOpen
If AcApp.CurrentProject.FullName <> "" Then
AcApp.UserControl = True
Else
AcApp.Quit
MsgBox "Failed to open '" & cDatabaseToOpen & "'."
End If