So I have decided to contribute a few of the more useful snippets of code I have put together in some of the better databases I have written.
I hope you guys find this useful:
"Get Directions in google maps from address fields":
You will need to change field names to suit.
This can cope with null fields and missing data, and will prompt you for more details. The address of origin is hard coded, buy could be replaced with a variable if need be.
"find phone number in white pages from name and address":
This one is designed to take a full name, and Glean the last name from it
You will need to change field names and such as appropriate.
I hope you guys find this useful:
"Get Directions in google maps from address fields":
You will need to change field names to suit.
This can cope with null fields and missing data, and will prompt you for more details. The address of origin is hard coded, buy could be replaced with a variable if need be.
Code:
Dim Address As String
Dim answer As String
Dim Phonenum As String
Dim VarContactName As String
'change this address to your current address or address that the database will be used
Address = "http://maps.google.com/?q=118+weird+st+timbucktu+to+"
On Error GoTo errhandler
'Streetnumber
ContactPostalAddress.SetFocus
If ContactPostalAddress.Text = "" Then
MsgBox "No street name or number entered!" & vbCrLf & "I will try to get directions to the town instead"
End If
Address = Address + ContactPostalAddress.Text + "+"
'Town
Township.SetFocus
If Township.Text = "" Then
answer = MsgBox("No Town name entered!" & vbCrLf & "Mapping will now abort!" & vbCrLf & "Do you have ANY idea where the job is?", vbYesNo + vbQuestion)
If answer = vbYes Then
MsgBox "In that case, I will display your current location in Google maps." & vbCrLf & "You can pan and zoom to your intended location." & vbCrLf & "Please remember to update the job card when you find the address."
Else
HomePhone.SetFocus
If HomePhone.Text = "" Then
Email.SetFocus
If Email.Text = "" Then
'insert employer/supervisor name and number here
MsgBox "As no Phone or Email has been entered for this job;" & vbCrLf & "Your best bet is to call the boss on:" & vbCrLf & "xxxxxxxxx"
Else
MsgBox "An email address has been detected for this job!" & vbCrLf & "I will now open a new email message for this address, so that you can ask them where this job is located."
Command56_Click
End If
Else
HomePhone.SetFocus
Phonenum = HomePhone.Text
ContactName.SetFocus
VarContactName = ContactName.Text
MsgBox "You should call " & ContactName & ", on: " & Phonenum & ", and ask them for directions." & vbCrLf & "Remember to update the job card when you have directions!"
End If
Exit Sub
End If
End If
Address = Address + Township.Text + "+"
'State
'insert current state, or variable/field name here
Address = Address + "Vic"
FollowHyperlink Address
'mapping code end
errhandler:
Exit Sub
This one is designed to take a full name, and Glean the last name from it
You will need to change field names and such as appropriate.
Code:
Dim VarLastName As String
Dim VarName As String
Dim URL As String
Dim myString As String
Dim myReplaceDemo As String
'VarName = ContactName.Value
ContactName.SetFocus
VarLastName = ContactName.Value
If VarLastName = "" Then
MsgBox "A Contact name is required for a phone number search" & vbCrLf & "Please enter one!"
Exit Sub
Else
VarLastName = Mid([ContactName], InStrRev([ContactName], " ") + 1)
URL = "http://www.whitepages.com.au/resSearch.do?subscriberName=" & VarLastName
If ContactPostalAddress.Value = "" Then
MsgBox "No postal address to search for!" & vbCrLf & "Aborting phone number search!"
Exit Sub
Else
myString = ContactPostalAddress.Value
myReplaceDemo = Replace(myString, " ", "+")
myString = myReplaceDemo
myReplaceDemo = Replace(myString, "road", "rd")
myString = myReplaceDemo
myReplaceDemo = Replace(myString, "Road", "rd")
myString = myReplaceDemo
URL = URL & "&givenName=&location=" & myReplaceDemo & "+Vic"
FollowHyperlink URL
End If
On Error GoTo Errcode
Errcode:
Exit Sub
End If