Hi, Ashley.
On another more complex note is it possible to have a message box come up
saying "This Job has no Work Instruction. Would You Like to add one?" - Yes
or No
and then do nothing if no is selected and open a file if yes is selected.
Yes. But with a caveat. Your Hyperlink is on an unattached label, and in
order to edit that Hyperlink, one must set focus to the control that stores
the Hyperlink. Unfortunately, one cannot set focus to an unattached label.
The solution of course is to use a text box. Unfortunately, only a bound
text box may hold a Hyperlink. Therefore, your table must store the
Hyperlink if you want this to work.
Here's the code (watch out for word wrap):
Private Sub ChkHypLinkBtn_Click()
On Error GoTo ErrHandler
Dim sDefaultDir As String
Dim sOrigText As String
Dim ans As Integer
If (Nz(Me!Work_Instruction.Value, "") = "") Then
ans = MsgBox("This Job has no Work Instruction." & vbCrLf & _
"Would You Like to add one?", vbInformation + vbYesNo, _
"No Work Instruction")
If (ans = vbYes) Then
sDefaultDir = "C:\Work" ' Default directory for the "Edit
Hyperlink" dialog box.
Me!txtHypLink.SetFocus
sOrigText = Me!txtHypLink.Text ' Save value in case
user doesn't edit the hyperlink.
Me!txtHypLink.Text = sDefaultDir
RunCommand acCmdEditHyperlink ' Call the "Insert/Edit
Hyperlink" dialog window.
'---------------------------------------------------------------------
' Determine whether user didn't edit the hyperlink.
'---------------------------------------------------------------------
If (Me!txtHypLink.Text = sDefaultDir) Then
Me!txtHypLink.Text = sOrigText ' Replace orig.
hyperlink string value.
End If
End If
End If
Exit Sub
ErrHandler:
If (Err.Number = 2501) Then ' User cancelled action.
Resume Next
Else
MsgBox "Error in ChkHypLinkBtn_Click( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
End If
End Sub
.... where "C:\Work" is the default directory and txtHypLink is the name of
the text box bound to a Hyperlink field.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.