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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expected literal constant error

Status
Not open for further replies.

sozzer

Technical User
Apr 4, 2005
73
0
0
GB
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


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
 
I wouldn't say it has to do with MSAccess
Code:
Dim AcApp
Dim oShell
Dim strUser
Dim strPath
[b]Dim cDatabaseToOpen[/b]

On Error Resume Next
Set oShell = Wscript.CreateObject("Wscript.Shell")

strUser = oShell.ExpandEnvironmentStrings("%UserName%")
strPath = "C:\Documents and Settings\" & strUser & "\Desktop\PET.mdb"

[b]cDatabaseToOpen = strpath[/b]

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top