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

Dynamic Path Name 2

Status
Not open for further replies.

onefootout

Technical User
Oct 23, 2007
42
US
This is driving me nuts!

I have a button that opens a MS word doc, but I have to enter the string, like so.


Private Sub Command0_Click()

Dim HWordDoc As String
Dim oApp As Object

HWordDoc = "C:\Whatever.doc"

If Dir(HWordDoc) = "" Then
MsgBox "Document Not Found"
Else
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Open Filename:=HWordDoc
DoCmd.Maximize

End If

End Sub

How can I make the path string into something dynamic, so a user could pick from a list and populate it? I have a table with path strings and associated names.

I tried using a query to at least pick the right name and path, and maybe set some variable and go from there, but that got me nowhere.

Can I code query commands in onClick events? Should I do this some other way? Arg! I'm just so stinking frustrated.
 
Why can't you populate a combo box from your table, and set HWordDoc = to its value?

Sure, the early bird gets the worm, but the second mouse gets the cheese in the trap.
 
It must be my code, because when I try that, and I click the button, and nothing happens. No error, no nothing.

Private Sub Command0_Click()

Dim HWordDoc As Object
Dim oApp As Object

HWordDoc = [pickname]

If Dir(HWordDoc) = "" Then
MsgBox "Document Not Found"
Else
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Open Filename:=HWordDoc
DoCmd.Maximize

End If

End Sub

It's selecting from a combo box, which has 2 columns, Name and Path. Do I have to somehow specify the 2nd column (path)?
 
How are ya onefootout . . .

. . . and this:
Code:
[blue]    Dim oApp As Object, HWordDoc [purple][b]As String[/b][/purple]

    HWordDoc = Me![purple][b]ComboboxName.Column(1)[/b][/purple]
    
    If Dir(HWordDoc) = "" Then
      MsgBox "Document Not Found"
    Else
      Set oApp = CreateObject("Word.Application")
      oApp.Visible = True
      oApp.Documents.Open Filename:=HWordDoc
      DoCmd.Maximize
    End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
YES!!! That works!

AceMan, you are the Acey-est of them all. Thank you too, genomon for pointing me in the correct direction! I was tearing my hair out!

For the record, the path name is in the 2nd column of the combo box. I set that column width to 0 (in the control properties) so it couldn't be seen.

Thanks Again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top