Consulting

Results 1 to 9 of 9

Thread: FollowHyperlink with parameters question

  1. #1
    VBAX Regular ptvGuy's Avatar
    Joined
    Jun 2004
    Location
    Far Northern California
    Posts
    10
    Location

    FollowHyperlink with parameters question

    Okay, here's a fun Access question:

    I'm trying to create a command button in my database that will take the donor address information from the current form and send it through the Internet to MapQuest to get a map and driving directions to the donor's business. However, I keep getting a "Compile Error: Object Required" message. I can't seem to figure out where I'm going wrong with this.

    Any help would be appreciated. Thanks.

    [VBA]Private Sub Mapper_Click()
    On Error GoTo Err_Mapper_Click
    Dim strAddress As String
    Set strAddress = "http://www.mapquest.com/maps/map.adp?city=" & _
    Str(Me![DonorCity]) & "%%26state=" & Str(Me![DonorState]) & _
    "%%26address=" & Str(Me![DonorAddress1]) & "%%26zip=" & _
    Str(Me![DonorZip]) & "%%26country=us%%26zoom=5"
    Application.FollowHyperlink strAddress, , True
    Exit_Mapper_Click:
    Exit Sub

    Err_Mapper_Click:
    MsgBox Err & ": " & Err.Description
    Resume Exit_Mapper_Click

    End Sub[/VBA]
    Last edited by Anne Troy; 06-23-2004 at 02:52 PM.
    -->ptvGuy

    KISS (Keep It Simple Stupid)

  2. #2
    VBAX Regular WillR's Avatar
    Joined
    May 2004
    Location
    Rugby - UK
    Posts
    60
    Location
    If strAddress id dimensioned as a String variable, I think the use of the Set command is what is causing the problem.... Set is used to determine "Objects"

    How does this work ?

    [vba]Private Sub Mapper_Click()
    On Error Goto Err_Mapper_Click
    Dim strAddress As String
    strAddress = "http://www.mapquest.com/maps/map.adp?city=" & _
    Str(Me![DonorCity]) & "%%26state=" & Str(Me![DonorState]) & _
    "%%26address=" & Str(Me![DonorAddress1]) & "%%26zip=" & _
    Str(Me![DonorZip]) & "%%26country=us%%26zoom=5"
    Application.FollowHyperlink strAddress, , True
    strAddress = vbnullstring
    Exit_Mapper_Click:
    Exit Sub

    Err_Mapper_Click:
    MsgBox Err & ": " & Err.Description
    Resume Exit_Mapper_Click

    End Sub [/vba]

    Haven't delvedtoo much into the rest of the code as I not overly familiar with the Access model, but the string issue was the first thing to hit me...
    Will
    Not all chemicals are bad. Without chemicals such as hydrogen and oxygen for example, there would be no way to make water, a vital ingredient in beer.

  3. #3
    VBAX Regular ptvGuy's Avatar
    Joined
    Jun 2004
    Location
    Far Northern California
    Posts
    10
    Location
    Thanks, I think you're right, but now I'm getting a "13: Type mismatch" error which doesn't make sense since all of the underlying fields are text fields. I even tried breaking it into seperate pieces which didn't help. I also just realized that both the DonorAddress and DonorCity fields either do or can contain spaces which means that I'm going to have to set something up in the code to find and replace all those spaces with plus signs to make the outgoing URL parameters valid. The really annoying part of all this is that it was just a little extra bit that I thought I'd throw into the database for the customer. It wasn't supposed to take this kind of time.

    [VBA]
    Private Sub Mapper_Click()
    On Error GoTo Err_Mapper_Click

    Dim strAddress As String
    Dim donCity As String
    Dim donState As String
    Dim donAddress As String
    Dim donZip As String

    donCity = Str(Me![DonorCity])
    donState = Str(Me![DonorState])
    donAddress = Str(Me![DonorAddress1])
    donZip = Str(Me![DonorZip])

    strAddress = "http://www.mapquest.com/maps/map.adp?city=" & donCity & "%%26state=" & donState & "%%26address=" & donAddress & "%%26zip=" & donZip & "%%26country=us%%26zoom=5"

    Application.FollowHyperlink strAddress, , True

    strAddress = vbNullString

    Exit_Mapper_Click:
    Exit Sub

    Err_Mapper_Click:
    MsgBox Err & ": " & Err.Description
    Resume Exit_Mapper_Click

    End Sub
    [/VBA]
    -->ptvGuy

    KISS (Keep It Simple Stupid)

  4. #4
    VBAX Regular
    Joined
    Aug 2004
    Location
    Mesquite, Texas
    Posts
    13
    Location
    This is a sample of code that will remove spaces and replace them with "+".
    [vba]
    Dim sHoldIt As String

    sHoldIt = "This is a test "

    'Remove trailing spaces
    sHoldIt = Trim(sHoldIt)

    'Change imbedded spaces with plus signs
    sHoldIt = Replace(sHoldIt, " ", "+", 1, , vbTextCompare)

    'of course you can combine them like
    'donAddress = Str(Replace(TRIM(Me![DonorAddress1]),, " ", "+", 1, , vbTextCompare))
    [/vba]

  5. #5
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hey, Scott! Cool. Would you mind adding that code to our knowledgebase?
    ~Anne Troy

  6. #6
    VBAX Regular ptvGuy's Avatar
    Joined
    Jun 2004
    Location
    Far Northern California
    Posts
    10
    Location

    SOLVED

    Quote Originally Posted by sgrant
    This is a sample of code that will remove spaces and replace them with "+".
    Okay, that was incredibly handy. Thanks a lot. Now I have a working command button (called "mapper") in my database that lets users instantly get a map from MapQuest without having to reenter the address information once they're at that site. That little piece of code could be useful for a lot of different situations. I'm hoping it becomes part of the knowledge base too.
    -->ptvGuy

    KISS (Keep It Simple Stupid)

  7. #7
    VBAX Regular
    Joined
    Jul 2004
    Location
    London, UK
    Posts
    15
    Location
    Not usre if you have a Access97 function for replace, there are plenty around, but here's one i prepaired earlier..

    see below

    Dave

  8. #8
    VBAX Regular
    Joined
    Jul 2004
    Location
    London, UK
    Posts
    15
    Location
    [VBA] Public Function Replace97(ByVal sString, sFind, sReplace) As String

    Dim iPos As Long
    Replace97 = sString
    If Len(sString) = 0 Then
    'zero length string
    Exit Function
    Else
    iPos = 1
    Do
    iPos = InStr(iPos, sString, sFind, vbBinaryCompare)
    If iPos > 0 Then
    Replace97 = Left(Replace97, iPos - 1) & sReplace & _
    Right(Replace97, Len(Replace97) - iPos)
    iPos = iPos + 1
    End If
    Loop While iPos > 0
    End If
    End Function

    [/VBA]

  9. #9
    VBAX Regular
    Joined
    Aug 2004
    Location
    Stratford, Connecticut USA
    Posts
    13
    Location
    I changed the function to be more generic so I didn't have to specify form field names but I couldn't get the posted string to work. So, I built a slightly different string.
    [VBA]Public Function Mapper_Click(strCity As Variant, strState As Variant, strAddress As Variant, strZip As Variant) As Variant
    On Error GoTo Err_Mapper_Click

    Dim strFullAddress As Variant
    Dim strMapquest As Variant
    strFullAddress = strAddress & "&city=" & strCity & "&state=" & strState & "&zipcode=" & strZip
    strMapquest = "http://www.mapquest.com/maps/map.adp...try=US&address=" & strFullAddress & "&historyid=&submit=Get Map"

    'Remove trailing spaces
    strMapquest = Trim(strMapquest)

    'Change imbedded spaces with plus signs
    strMapquest = Replace(strMapquest, " ", "+", 1, , vbTextCompare)

    Application.FollowHyperlink strMapquest, , True

    strMapquest = vbNullString

    Exit_Mapper_Click:
    Exit Function

    Err_Mapper_Click:
    MsgBox Err.Number & "-" & Err.Description
    Resume Exit_Mapper_Click

    End Function
    [/VBA]
    Bridge Players Know ALL the Tricks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •