open specific word doc in Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm opening a notepad (.txt) using the RunApp in my forms Macro. How can I
get this particular button to open the corresponding .txt file? e.g. the
record with ID # 1003 should open 1003.txt when this button is clicked on. Is
this possible?
 
There's no need to use RunApp.

If Notepad is the default text editor, or if you're happy to have the
file open in the user's default text editor, you can just use something
like this:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

(where txtID is the name of the textbox that's displaying the ID
number).

If you want to use Notepad even if it's not the user's preferred editor,
use the VBA Shell() function, something like this:

Shell "Notepad.exe """ & strFolder & Me.txtId.Value & ".txt"""
 
Thanks, sweetie.

John Nurick said:
There's no need to use RunApp.

If Notepad is the default text editor, or if you're happy to have the
file open in the user's default text editor, you can just use something
like this:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

(where txtID is the name of the textbox that's displaying the ID
number).

If you want to use Notepad even if it's not the user's preferred editor,
use the VBA Shell() function, something like this:

Shell "Notepad.exe """ & strFolder & Me.txtId.Value & ".txt"""
 
What I suggested was:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

You've inserted "notepad.exe" in two places where it doesn't belong. The
"Application" in Application.FollowHyperlink refers to the Access
Application object, not to the application you want to open, and all
that's needed for the hyperlink is the path to the file, e.g.

C:\Documents and Settings\ICandi\My Documents\XXX\1001.xls
 
OK. This is exactly what I have in VB (where 'Notes' is no longer a button
on the form but a hyperlink:

Private Sub Label78_Click()

Dim strFolder As String
strFolder = "C:\Documents and Settings\ . . . \Notes\"
Application.FollowHyperlink strFolder & Me.Proposal_ID.Value & ".txt"

End Sub

And this is the error message I'm getting:

The expression OnClick you entered as the event property setting produced
the following error:
Expected Text or Binary.
*The expression of a macro, the name of a user-defined function, or [Event
Procedure].
*There may have been an error evaluating the function, event, or macro.
 
In form design view, select Label78 and open the Properties dialog. In
the Events tab, make sure that On Click is set to [Event Procedure].

OK. This is exactly what I have in VB (where 'Notes' is no longer a button
on the form but a hyperlink:

Private Sub Label78_Click()

Dim strFolder As String
strFolder = "C:\Documents and Settings\ . . . \Notes\"
Application.FollowHyperlink strFolder & Me.Proposal_ID.Value & ".txt"

End Sub

And this is the error message I'm getting:

The expression OnClick you entered as the event property setting produced
the following error:
Expected Text or Binary.
*The expression of a macro, the name of a user-defined function, or [Event
Procedure].
*There may have been an error evaluating the function, event, or macro.


John Nurick said:
What I suggested was:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

You've inserted "notepad.exe" in two places where it doesn't belong. The
"Application" in Application.FollowHyperlink refers to the Access
Application object, not to the application you want to open, and all
that's needed for the hyperlink is the path to the file, e.g.

C:\Documents and Settings\ICandi\My Documents\XXX\1001.xls
 
Okay, I know I'm having trouble, but I'm not a complete idiot. :). Seriously,
that's done, I double checked. U think this has something to do with my
folders having spaces in their names?

John Nurick said:
In form design view, select Label78 and open the Properties dialog. In
the Events tab, make sure that On Click is set to [Event Procedure].

OK. This is exactly what I have in VB (where 'Notes' is no longer a button
on the form but a hyperlink:

Private Sub Label78_Click()

Dim strFolder As String
strFolder = "C:\Documents and Settings\ . . . \Notes\"
Application.FollowHyperlink strFolder & Me.Proposal_ID.Value & ".txt"

End Sub

And this is the error message I'm getting:

The expression OnClick you entered as the event property setting produced
the following error:
Expected Text or Binary.
*The expression of a macro, the name of a user-defined function, or [Event
Procedure].
*There may have been an error evaluating the function, event, or macro.


John Nurick said:
What I suggested was:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

You've inserted "notepad.exe" in two places where it doesn't belong. The
"Application" in Application.FollowHyperlink refers to the Access
Application object, not to the application you want to open, and all
that's needed for the hyperlink is the path to the file, e.g.

C:\Documents and Settings\ICandi\My Documents\XXX\1001.xls


On Mon, 23 Jan 2006 13:50:06 -0800, "I.Candi"

This is what I have in VB:

Private Sub Notes_Click()
Dim strFolder As String
strFolder = "notepad.exe C:\Documents and Settings\ . . ."
notepad.exe.FollowHyperlink strFolder & Me.ProposalID.Value & ".txt"

But I can't get it to work. For example, if the user is in the record with
Proposal ID 1001, I want them to be able to click on notes and the
corresponding .txt file (1001.txt) should open. What am i doing wrong?


:

There's no need to use RunApp.

If Notepad is the default text editor, or if you're happy to have the
file open in the user's default text editor, you can just use something
like this:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

(where txtID is the name of the textbox that's displaying the ID
number).

If you want to use Notepad even if it's not the user's preferred editor,
use the VBA Shell() function, something like this:

Shell "Notepad.exe """ & strFolder & Me.txtId.Value & ".txt"""


On Fri, 20 Jan 2006 08:59:04 -0800, "I.Candi"

I'm opening a notepad (.txt) using the RunApp in my forms Macro. How can I
get this particular button to open the corresponding .txt file? e.g. the
record with ID # 1003 should open 1003.txt when this button is clicked on. Is
this possible?
 
If you're using Application.FollowHyperlink, spaces in folder or file
names shouldn't be a problem. (It's a little different if you're
assembling a command line to pass to Shell()).

But try this:

Private Sub Label78_Click()

Dim strFolder As String
Dim strPath As String

strFolder = "C:\Documents and Settings\ . . . \Notes\"

strPath = strFolder & Me.Proposal_ID.Value & ".txt"

MsgBox "About to try and open " & vbCrLf & strPath

Application.FollowHyperlink strPath

End Sub

The messagebox will let you see whether the path you have assembled
actually leads to a file.

Okay, I know I'm having trouble, but I'm not a complete idiot. :). Seriously,
that's done, I double checked. U think this has something to do with my
folders having spaces in their names?

John Nurick said:
In form design view, select Label78 and open the Properties dialog. In
the Events tab, make sure that On Click is set to [Event Procedure].

OK. This is exactly what I have in VB (where 'Notes' is no longer a button
on the form but a hyperlink:

Private Sub Label78_Click()

Dim strFolder As String
strFolder = "C:\Documents and Settings\ . . . \Notes\"
Application.FollowHyperlink strFolder & Me.Proposal_ID.Value & ".txt"

End Sub

And this is the error message I'm getting:

The expression OnClick you entered as the event property setting produced
the following error:
Expected Text or Binary.
*The expression of a macro, the name of a user-defined function, or [Event
Procedure].
*There may have been an error evaluating the function, event, or macro.


:

What I suggested was:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

You've inserted "notepad.exe" in two places where it doesn't belong. The
"Application" in Application.FollowHyperlink refers to the Access
Application object, not to the application you want to open, and all
that's needed for the hyperlink is the path to the file, e.g.

C:\Documents and Settings\ICandi\My Documents\XXX\1001.xls


On Mon, 23 Jan 2006 13:50:06 -0800, "I.Candi"

This is what I have in VB:

Private Sub Notes_Click()
Dim strFolder As String
strFolder = "notepad.exe C:\Documents and Settings\ . . ."
notepad.exe.FollowHyperlink strFolder & Me.ProposalID.Value & ".txt"

But I can't get it to work. For example, if the user is in the record with
Proposal ID 1001, I want them to be able to click on notes and the
corresponding .txt file (1001.txt) should open. What am i doing wrong?


:

There's no need to use RunApp.

If Notepad is the default text editor, or if you're happy to have the
file open in the user's default text editor, you can just use something
like this:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

(where txtID is the name of the textbox that's displaying the ID
number).

If you want to use Notepad even if it's not the user's preferred editor,
use the VBA Shell() function, something like this:

Shell "Notepad.exe """ & strFolder & Me.txtId.Value & ".txt"""


On Fri, 20 Jan 2006 08:59:04 -0800, "I.Candi"

I'm opening a notepad (.txt) using the RunApp in my forms Macro. How can I
get this particular button to open the corresponding .txt file? e.g. the
record with ID # 1003 should open 1003.txt when this button is clicked on. Is
this possible?
 
OH BLESS YE MIGHTY SURVEYOR OF ACCESS AND VISUAL BASIC ALIKE!
You'll never guess what was giving me the error. I kept leaving off the last
"\" in my path to the file I was using. If only I hadn't pitched 3 monitors
out of the window in frustration . . .

Thanks a million.

John Nurick said:
If you're using Application.FollowHyperlink, spaces in folder or file
names shouldn't be a problem. (It's a little different if you're
assembling a command line to pass to Shell()).

But try this:

Private Sub Label78_Click()

Dim strFolder As String
Dim strPath As String

strFolder = "C:\Documents and Settings\ . . . \Notes\"

strPath = strFolder & Me.Proposal_ID.Value & ".txt"

MsgBox "About to try and open " & vbCrLf & strPath

Application.FollowHyperlink strPath

End Sub

The messagebox will let you see whether the path you have assembled
actually leads to a file.

Okay, I know I'm having trouble, but I'm not a complete idiot. :). Seriously,
that's done, I double checked. U think this has something to do with my
folders having spaces in their names?

John Nurick said:
In form design view, select Label78 and open the Properties dialog. In
the Events tab, make sure that On Click is set to [Event Procedure].

On Tue, 24 Jan 2006 14:00:28 -0800, "I.Candi"

OK. This is exactly what I have in VB (where 'Notes' is no longer a button
on the form but a hyperlink:

Private Sub Label78_Click()

Dim strFolder As String
strFolder = "C:\Documents and Settings\ . . . \Notes\"
Application.FollowHyperlink strFolder & Me.Proposal_ID.Value & ".txt"

End Sub

And this is the error message I'm getting:

The expression OnClick you entered as the event property setting produced
the following error:
Expected Text or Binary.
*The expression of a macro, the name of a user-defined function, or [Event
Procedure].
*There may have been an error evaluating the function, event, or macro.


:

What I suggested was:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

You've inserted "notepad.exe" in two places where it doesn't belong. The
"Application" in Application.FollowHyperlink refers to the Access
Application object, not to the application you want to open, and all
that's needed for the hyperlink is the path to the file, e.g.

C:\Documents and Settings\ICandi\My Documents\XXX\1001.xls


On Mon, 23 Jan 2006 13:50:06 -0800, "I.Candi"

This is what I have in VB:

Private Sub Notes_Click()
Dim strFolder As String
strFolder = "notepad.exe C:\Documents and Settings\ . . ."
notepad.exe.FollowHyperlink strFolder & Me.ProposalID.Value & ".txt"

But I can't get it to work. For example, if the user is in the record with
Proposal ID 1001, I want them to be able to click on notes and the
corresponding .txt file (1001.txt) should open. What am i doing wrong?


:

There's no need to use RunApp.

If Notepad is the default text editor, or if you're happy to have the
file open in the user's default text editor, you can just use something
like this:

Dim strFolder As String
...
strFolder = "C:\Folder where my files are\"
Application.FollowHyperlink strFolder & Me.txtID.Value & ".txt"

(where txtID is the name of the textbox that's displaying the ID
number).

If you want to use Notepad even if it's not the user's preferred editor,
use the VBA Shell() function, something like this:

Shell "Notepad.exe """ & strFolder & Me.txtId.Value & ".txt"""


On Fri, 20 Jan 2006 08:59:04 -0800, "I.Candi"

I'm opening a notepad (.txt) using the RunApp in my forms Macro. How can I
get this particular button to open the corresponding .txt file? e.g. the
record with ID # 1003 should open 1003.txt when this button is clicked on. Is
this possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top