I have a database which stores entries from user.
in Cells D2:D100 are Works Order Numbers,
in Cells R2:R100 are hyperlinks to a PDF that is corresponding to that works order number.
I would like to write some code in which users enters a works order number in cell C3 of the "print documents sheet"
It will then search the "Database" sheet for that works order number, and then when it has found it, it prints the PDF which is in Cell R at the end of the row in which the works order number is in.
I have started writing some code to do this, I have written some code that loops through the rows and finds the work order number. However i am not sure how to do the inbetween bit, which is to print the pdf at the end of the row.
any help would be greatly appreciated, see starter code below
in Cells D2:D100 are Works Order Numbers,
in Cells R2:R100 are hyperlinks to a PDF that is corresponding to that works order number.
I would like to write some code in which users enters a works order number in cell C3 of the "print documents sheet"
It will then search the "Database" sheet for that works order number, and then when it has found it, it prints the PDF which is in Cell R at the end of the row in which the works order number is in.
I have started writing some code to do this, I have written some code that loops through the rows and finds the work order number. However i am not sure how to do the inbetween bit, which is to print the pdf at the end of the row.
any help would be greatly appreciated, see starter code below
VBA Code:
Dim iRow As Long 'Variable to hold the starting row and loop through all records in database
Dim sh As Worksheet 'worksheet variable to refer to where database is stored
Dim myValue As Variant
Dim WorksOrder As String
Dim Found As Boolean
'Get user entered WorksOrder Number
WorksOrder = ThisWorkbook.Sheets("PrintDocuments").Range("C3").Value
'Set worksheet
Set sh = ThisWorkbook.Sheets("Database")
iRow = 2 'row in which data starts from in database
Found = False
Do While sh.Range("A" & iRow).Value <> "" 'loop through until no data is found (last row of database)
If WorksOrder = sh.Range("D" & iRow).Value Then
Found = True
'Insert print PDF code here
Exit Do
End If
iRow = iRow + 1
Loop
If Found = True Then
MsgBox ("Document Printed")
Else
MsgBox ("Works Order Number Not Found")
End If
End Sub