Open up the associated file

Infinite

More left to learn.
Local time
Today, 05:52
Joined
Mar 16, 2015
Messages
402
Hello! I have lots of items, and each item has a label for it that I can print out. What I would like, is that I can have a command button named "print labels" And when the user clicks that, it prints the correct label for that gun. How would I go about doing that? I also have around 80 items, so a label for each gun would get very annoying, and I would have to add more code per gun, and that would become a large hassle. Thanks for the help in advance! :)
 
What items? I have a tblItems that has each item, and a qryItems that has all the info from the items.
 
Ish. I want it to open the corresponding Word doc. I know how to open a form up, but not open up a word doc from access.
 
ShellExecute, Shell and FollowHyperlink are options.
 
Code:
Private Sub Print_Label_DblClick(Cancel As Integer)
Call GoHyperlink("C:\Users\User\Desktop\!Labels\[Model]")
End Sub


That is what I want. I'm just not sure how to get the [Model] part to work...Because, it would just get its name for the file, from the name that is open on the form. I'm just not sure how I would get it to do that.
 
Try

Call GoHyperlink("C:\Users\User\Desktop\!Labels\" & Me.Model)
 
That first shows it red, and 2nd, it doesnt let my use it. It just errors.
 
GoHyperlink is something custom; have you added it in a standard module? Is the form control name correct, and the rest of the path? Looks a little funky with the "!" in there.
 
GoHyperlink is something custom; have you added it in a standard module?

Yes, I have.


Looks a little funky with the "!" in there.

Ya, thats just how I name the important folders I have.
 
Well, what error do you get? On what line? I don't normally use Call, but it should work. If memory serves, you include parentheses with call, none without. If I copy that line into VBA, it isn't red.
 
Error 490: Cannot open the specified file.

That is the error im getting. And, yes, I am positive that I have the correct path.

I changed it from !Labels to labels. In case that was doing something.

How do I add .doc onto the ending?

I think that is the problem. If I put Bazooka in it, it errors, but if I put Bazooka.doc into it, it works. How would I add that onto the end also?
 
Last edited:
Call GoHyperlink("C:\Users\User\Desktop\!Labels\" & Me.Model & ".doc")
 
That does it! Thanks! Now, one last thing, how would I print that on open? Like, have it print that?
 
Not sure with Word. I do it with Excel using automation. The relevant bits:

Set xl = CreateObject("excel.application")
strFile = "\\ServerName\FolderName\" & strPMI
xl.Workbooks.Open (strFile)
xl.ActiveWindow.SelectedSheets.PrintOut
xl.Quit
 
Code:
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "C:\Users\User\Desktop\Labels\" & Me.Model & ".doc"
WordObj.PrintOut Background:=False
WordObj.Quit
Set WordObj = Nothing

Got it! Combining your code, and some other code I found, I can now print with a click of a button! Now, the last thing, how would I go about printing it twice?
Asides from clicking it twice. I guess that doesnt matter. The user can just click it again, and again to print it more.

Thanks a TON for your help!
 
Last edited:
I would assume you can just repeat this line:

WordObj.PrintOut Background:=False
 
Yes, but what if the user only wanted 1? Or then 2? That is why im thinking just printing one at a time should be good, and if they want more, to click more :)

Thanks again!
 
Just thought of something. How would I go about doing this, but with a multi select?

Thanks!

EDIT: That is going to be a LOT harder then I thought...

I got this code, and it gets me what is selected. Im just not sure what to do with that.

Code:
Private Sub Command6_Click()
Dim ItemIndex As Variant
For Each ItemIndex In Me.lstPrint.ItemsSelected
    MsgBox Me.lstPrint.ItemData(ItemIndex)
Next
End Sub

Maybe have it populate a text box? But, I would have....Maybe not. That opens up a message box. Maybe just replace the message box with the print?
 
Last edited:
Code:
Private Sub Command2_Click()

Dim ItemIndex As Variant
For Each ItemIndex In Me.lstPrint.ItemsSelected
      Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "C:\Users\User\Desktop\Labels\" & Me.lstPrint.ItemData(ItemIndex) & ".doc"
WordObj.PrintOut Background:=False
WordObj.Quit
Set WordObj = Nothing

Next


End Sub

That does it!
I cant believe it! took me like 5 minutes of googling around, and now I can select them, and they print. The ones I select, that is.

That is sooo nice getting that done. Thanks a TON man! Have a Great weekend!
 

Users who are viewing this thread

Back
Top Bottom