Is it possible to add a hyperlink to a messagebox? I'm trying to do something like this:
MsgBox "Sorry, but you have an out-of-date database version. Please redownload via the batch file to ensure that you have the latest version. Contact the administrator of this database or your manager if you need help." & vbCr _
& vbCr _
& "Your current database version is " & CurrentVer & " which may be out of date. The current database version prescribed on the network share is " & FileVer & ". They must match in order for you to proceed." & vbCr _
& vbCr _
& "For CSC self-help instructions on how to reload the most current version of the PRF Intake Tool to your computer, please click the link below to be directed to CSC Online instructions." & vbCr _
& vbCr _
& "http://www.OurSite.com/online/Solutions/Search_Results.asp?opsystem=7&keywords=PRF+Intake+Tool&Category=", , "There is a problem..."
The problem is, the hyperlink isn't clickable. I'd like to do this so that the users can just click the link and have the download begin automatically.
I'm using Access 2010 in a Win7 environment.
A straight-forward answer is NO. MsgBox does not allow hyperlinks, just plain text.
Thus, here is a workaround that should work alright.
Set objShell = CreateObject("Wscript.Shell")
intMessage = MsgBox("Sorry, but you have an out-of-date database version. Please redownload via the batch file to ensure that you have the latest version. Contact the administrator of this database or your manager if you need help." & vbCr _
& vbCr _
& "Your current database version is " & CurrentVer & " which may be out of date. The current database version prescribed on the network share is " & FileVer & ". They must match in order for you to proceed." & vbCr _
& vbCr _
& "Would you like to learn more about CSC self-help instructions on how to reload the most current version of the PRF Intake Tool to your computer?", _
vbYesNo, "There is a problem...")
If intMessage = vbYes Then
objShell.Run ("http://www.OurSite.com/online/Solutions/Search_Results.asp?opsystem=7&keywords=PRF+Intake+Tool&Category=")
Else
Wscript.Quit
End If
If underline style is a requirement, then you should just create your own User Form as described at http://j-walk.com/ss/excel/tips/tip71.htm. Here are the steps:
Add a Label object and type your message
Make the Label blue (ForeColor) and underlined (Font) so it looks like a typical hyperlink.
Set the Label's MousePointer property to 99 - fmMousePointerCustom
Specify the cursor file for the Label's MouseIcon image (if you have one).
Double-click the Label and create a subroutine the Click event. Here's a sample code:
Private Sub Label1_Click()
Link = "http://www.YOUR_SITE.com"
On Error GoTo NoCanDo
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
Unload Me
Exit Sub
NoCanDo:
MsgBox "Cannot open " & Link End Sub
To create a "mail to" hyperlink, use a statement like this:
Link = "mailto:someone#somewhere.com"
Related
I'm trying to create a search box that acts like the navigation search function at the bottom of the page in access. This is so the users of my data base have an easier time navigating the database.
My code currently is
Private Sub cmdSearch_Click()
Dim bkmk As Variant
Dim strField As String
Me.RecordsetClone.MoveFirst
'Find the first record that matches what
'is in the search text box.
Me.RecordsetClone.FindFirst "B3 Like " _
& Chr(34) & Me.txtsearch & "*" & Chr(34) _
& "OR Item Like" _
& Chr(34) & Me.txtsearch & "*" & Chr(34) _
If Me.RecordsetClone.NoMatch Then
MsgBox "No Match"
Else
bkmk = Me.RecordsetClone.Bookmark
Me.Recordset.Bookmark = bkmk
End If
End Sub
When I apply this code to my search function even when I'm testing with an item that is known to be in the database it is returning the "No Match" message box. My end goal is to have a search function that will search multiple fields in the back end table.
I have created a VB windows form Application with text boxes and a datagridview.
The idea is for the user to enter information onto the text boxes, and then click a button to save to the grid view. This works fine, but when closing the application and reopening the data is gone.
The below code is what i use to save the data to the grid view.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rnum As Integer = DataGridView1.Rows.Add()
If Me.CheckBox1.Checked = True Then
Clipboard.SetText("Situation:" & vbNewLine & Me.TextBox1.Text & vbNewLine & vbNewLine & "Actions:" & vbNewLine & Me.TextBox2.Text & vbNewLine & vbNewLine & "Next Steps:" & vbNewLine & Me.TextBox3.Text & vbNewLine & vbNewLine & "Notes:" & vbNewLine & Me.TextBox4.Text)
Else
Clipboard.SetText("Situation:" & vbNewLine & Me.TextBox1.Text & vbNewLine & vbNewLine & "Actions:" & vbNewLine & Me.TextBox2.Text & vbNewLine & vbNewLine & "Next Steps:" & vbNewLine & Me.TextBox3.Text)
End If
DataGridView1.Rows.Item(rnum).Cells("Situation").Value = Me.TextBox1.Text
DataGridView1.Rows.Item(rnum).Cells("Actions").Value = Me.TextBox2.Text
DataGridView1.Rows.Item(rnum).Cells("NextSteps").Value = Me.TextBox3.Text
DataGridView1.Rows.Item(rnum).Cells("SupportingDocuments").Value = Me.TextBox4.Text
MsgBox("Added to Clipboard")
End Sub
The application is used by different users on different machine, so i want the gridview to have saved what that individual user has added.
I know im missing something easy, like adding a dataset but wouldnt this have to be on a static location used by everyone? And i also looked into xml files but cannot seem to find what im looking for.
Any help would be greatly appreciated.
All you have to do is to select your database in Project Explorer and navigate to its properties. In its properties, set "Copy to Output folder = Copy if Newer"
After trying to work around databases, but only seeming to get them static. I worked on using code to create xml files on the user profile, and then loading them.
This Link helped me alot
I use the following VBA to open a message box:
Sub Message()
MsgBox ("Do you want create a file on your desktop?" _
& vbCr & " " _
& vbCr & "Once you click yes an unprotected file with all sheets visible will be saved on your desktop and opened. You can immediately start working with this file.")
End Sub
All this works fine.
However, as you can see in the screenshot the word "file" goes in a different line. Is it possible to format the messagebox or change the VBA code so the word "file" does not appear in a different line?
It depends on the resolution of the PC of the user. In my case I even get it like this:
If you want to control the lines, then you should write a custom form. There you would have much better control over the display, and if you play a bit with its properties, you would mimic exactly the MsgBox():
Some sample code, Label1 is a label element:
Private Sub UserForm_Initialize()
Me.Label1 = "Do you want create a file on your desktop?" _
& vbCr & " " _
& vbCr & "Once you click yes an unprotected file with all sheets visible will be saved on your desktop and opened." & _
vbCrLf & "You can immediately start working with this file."
End Sub
Perhaps adjust your code with line breaks to suit. For example:
Sub Message()
MsgBox ("Do you want create a file on your desktop?" _
& vbCr & " " _
& vbCr & "Once you click yes an unprotected file" _
& vbCr & " " _
& vbCr & "with all sheets visible will be saved on your desktop and opened." _
& vbCr & " " _
& vbCr & "You can immediately start working with this file.")
End Sub
I have a MainMenu where the user can enter a SchoolID in a search bar (txtSearchBar) and when they click on the SearchBySchoolID button, it opens the form, SchoolForm, based on the SchoolID. Sometimes the user clicks the SearchBySchoolID button without entering anything in the txtSearchBar so when the code below is executed, SchoolForm still opens but it is all blank.
What can I add to my code below so that a message box saying "No SchoolID found" pops up instead of bringing the user to a blank SchoolForm when they type nothing into my search bar?
Private Sub SearchBySchoolID_Click()
Dim txtSearchBar As String
On Error GoTo ErrorIDSearch
DoCmd.OpenForm "SchoolForm", , , "SchoolID = " & ("""" &
Me.txtSearchBar.Value & """"), acFormReadOnly
ExitErrorIDSearch:
Exit Sub
ErrorSIDSearch:
If Err.Number = 3075 Then
MsgBox "Please enter a valid SchoolID."
Else
MsgBox "The following error has occured:" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & vbCrLf & , _
vbCritical, "An Error has Occured!"
Resume ExitErrorIDSearch
End If
End Sub
You have two choices
Either put your event handling in the OnOpen event of the form named SchoolForm (and maybe use OpenArgs or an invisible textbox to set some kind of Status on that form so it knows where it was opened from, and why)
or simpler:
Check for existence of the SchoolID in the table before attempting to open SchoolForm
Could use a DLookup or a DCount
e.g.
If DCount("SchoolID", "YourTableOrQueryForSchools", "SchoolID=" & """" & Me.txtSearchBar.Value & """") = 0 Then
MsgBox "Please enter a valid SchoolID.", 64, "Try Again"
Me.txtSearchBar = ""
Me.txtSearchBar.Setfocus
Else
DoCmd.OpenForm "SchoolForm", , , "SchoolID = " & """" & Me.txtSearchBar.Value & """", acFormReadOnly
End If
I have written a VB.net executable that deletes a file then transfers a different one in it's place. An extract of the code is shown below. The problem is it fails every time due to the program that uses the file recreates it immediately after deletion.
How can I delete the file and prevent it being replaced? I cannot change anything about the program that's recreating it.
If IO.File.Exists(AMPDir & "AMP_DIR.DAT") = False Then
MsgBox("The following file is missing..." & vbCrLf & vbCrLf & " " & "AMP_DIR.DAT", MsgBoxStyle.Critical, "Error...")
Me.Close()
End
ElseIf IO.File.Exists(AMPDir & "AMP_DIR.DAT") = True And IO.File.Exists(LOGDir & "LOGIC.INF") = True Then
System.IO.File.Delete(AMPDir & "AMP_DIR.DAT")
System.IO.File.Copy(Path.GetDirectoryName(ConfigFile) & "\" & "AMP_DIR.DAT.IND", AMPDir & "AMP_DIR.DAT")
System.IO.File.SetAttributes(AMPDir & "AMP_DIR.DAT", FileAttributes.Normal)
End If