Link to home
Start Free TrialLog in
Avatar of jbotts
jbotts

asked on

Chr(34) function not working in MS Access 2010

The following code works in MS Access 2007 but not 2010. "Compile Error: Can't find project or library.

Dim path As String
Dim dir As String
Dim wdpath As String

dir = MFunctions.ReadFile("CL_FileDir.txt")
path = "C:\" & dir & "\" & fn & ".docx"
wdpath = "WinWord.exe" & " " & Chr(34) & path & Chr(34)
Avatar of byundt
byundt
Flag of United States of America image

Have you set a reference to MFunctions?
Have you declared fn and provided it a value?

Absent those issues, your code is compiling in my copy of Access 2010
Avatar of jbotts
jbotts

ASKER

In the Tools/References I do not find MFunctions. I have not declared fn and provided a value. I don't understand. Below is the code for the sub:
Public Sub OpenDoc(fn As String)
On Error GoTo PROC_ERR
    Dim path As String
    Dim dir As String
    Dim wdpath As String

    dir = MFunctions.ReadFile("CL_FileDir.txt")
    path = "C:\" & dir & "\" & fn & ".docx"
       
    wdpath = "WinWord.exe" & " " & Chr(34) & path & Chr(34)

    Shell wdpath, vbNormalFocus
PROC_EXIT:
    Exit Sub
PROC_ERR:
    MsgBox Err.Description & ": " & Err.Number
    Resume PROC_EXIT
End Sub
When I put sub OpenDoc in a module sheet of a new database, the compiler rejects the statement using MFunctions--saying "Variable not defined"

Given the rest of that statement, I speculated that MFunctions might be an object in a library that you had set a reference to in Access 2007, but which you had not done so for Access 2010.
Avatar of jbotts

ASKER

byundt, my apology. MFunctions is a module and ReadFile a defined function. The code is below:

Public Function ReadFile(FName) As String
On Error GoTo PROC_ERR

    Dim fso As FileSystemObject
    Dim tso As TextStream
    Dim result As String
    Dim fpath As String
       
    fpath = MFunctions.GetDBPath & FName
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tso = fso.OpenTextFile(fpath, ForReading)
    result = tso.ReadLine()
    ReadFile = result
PROC_EXIT:
    Exit Function
PROC_ERR:
    MsgBox Err.Description
    Resume PROC_EXIT
   
End Function
Avatar of jbotts

ASKER

I also got an error for the declaration:

Dim fso as FileSystemObject

Thanks
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbotts

ASKER

I don't find that reference. I tried Microsoft Script 1.0 and Microsoft Scriptlet but still ge the same compile error for Chr()
Almost certainly a Reference issue. You might try unchecking a reference, then closing the REf dialog, reopen it and re-check that reference.

You should also try a Debug - Compile (from the VBA Editor window). Fix any errors you find there, and continue doing that until the Compile menuitem is disabled.
Well instead of adding the reference, you could use late binding like so:

Dim fso As Object
Dim fsoStream As Object
'initialise the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")