Using a "field name" in a RunApp command?

seanmcq

New member
Local time
Today, 10:30
Joined
Mar 5, 2008
Messages
2
Hello, a little background from me:

I have a database for customers and the key field is "Customer Number" (1,2,3,4....). I have an invoice for each customer which has their customer number (eg. 1price.doc, 2price.doc). I would like to be able to use a button that opens the invoice for that specific customer.

I can use RunApp and in the command line put "C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" "C:\Documents and Settings\Work\My Documents\Customer Files\1price.doc"

This works fine but will always open 1price.doc. I would like to change the macro so it uses the "Customer Number" field, so if I am on customer 43, and click the button to "View Invoice", it opens 43price.doc.

I hope I have explained this correctly and many thanks for your help

Sean
 
this might be a better way...

Private Sub Command0_Click()
Dim stdocPath As String

stdocPath = "C:\" & Me.Combo1.Value

Application.FollowHyperlink stdocPath
End Sub


I hardcoded the path, but you could easily include it in a table just like I did with the Filename.

you will have to edit the filenames in the table and either edit the path in the code ( behind button on click event) or place you files in the C:\ directory
 
Ziggy, I'm not sure I totally understand what you mean. I do not understand VB too well, but I don't see how your code works. I tried to modify it a little, but when I click the button, nothing happens. Can you advise where I am going wrong?

Code:
Private Sub Command0_Click()
Dim stdocPath As String

stdocPath = "C:\Documents and Settings\Work\My Documents\Files\" & Me.[Customer Number] & "price.doc"

Application.FollowHyperlink stdocPath
End Sub
 
sorry, I thought I uploaded the sample DB that I setup...it's on my other PC so I'll either upload it later tonight or make up a new one later...

but set it up like this....

first make a table to store your document names

2nd make a form add a combo (Assume it is called combo1) that looks up your the documents field from the table, add a button and place the code in the onclick event (you will find it in the properties of the button).


Code:
Private Sub Command0_Click()
Dim stdocPath As String

stdocPath = "C:\Documents and Settings\Work\My Documents\Files\" & Me.Combo1.Value

Application.FollowHyperlink stdocPath
End Sub
I changed it slightly from what you did because the object here is for you to be able to select which document you want to open....so the path is hardcoded and it is combined with the results of the combo to form the full string required to open the file.
 
Sean,

I got off topic in my suggestion, although it does work to open a specific report, you were on the right track with this... ( don't need a table as I had in my suggestion)...

Code:
Private Sub Command0_Click()
Dim stdocPath As String

stdocPath = "C:\Documents and Settings\Work\My Documents\Files\" & Me.[Customer Number] & "price.doc"

Application.FollowHyperlink stdocPath
End Sub

This should work for you, but the Me.[Customer Number] reference should be the control name not the name of your field.
 

Users who are viewing this thread

Back
Top Bottom