Solved

Chr(34) function not working in MS Access 2010

Posted on 2013-05-21
9
1,238 Views
Last Modified: 2013-05-21
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)
0
Comment
Question by:jbotts
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 39186180
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
0
 

Author Comment

by:jbotts
ID: 39186200
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
0
 
LVL 81

Expert Comment

by:byundt
ID: 39186207
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.
0
 

Author Comment

by:jbotts
ID: 39186212
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
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:jbotts
ID: 39186216
I also got an error for the declaration:

Dim fso as FileSystemObject

Thanks
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39186233
To use FileSystemObject, I believe you need to set a reference to Microsoft Scripting Runtime in Tools/References.
0
 

Author Comment

by:jbotts
ID: 39186249
I don't find that reference. I tried Microsoft Script 1.0 and Microsoft Scriptlet but still ge the same compile error for Chr()
0
 
LVL 84
ID: 39186267
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.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39186273
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")
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Office.Com /myAccount 9 41
Two list boxes - best structure 3 33
append to an ms access field 6 26
VBA code won't run Delete Query 5 26
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now