Results 1 to 12 of 12
  1. #1
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7

    Form Button with VB Code Does Nothing

    I am trying to make a button that opens an external browser for excel with a website.

    I put the button on the form (name it FindPhone), right click, and build event.
    In Visual Basic, I put in

    Code:
    Private Sub FindPhone_Click()
    Application.FollowHyperlink "www.google.ca"
    End Sub
    I close Visual Basic, and back in Access, I put the form in 'form view' and click the button. And nothing happens. What am I doing wrong?


    (Access 2007)

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you may want to check the property sheet behind the button. Access has been known to create events from dialogs and then not register the code link with the click event. Don't ask me why.

    This also happens if you write the code yourself and don't establish the link. If that's what's wrong, you can fix it by going to the click event on the prop sheet and click on the elipses (...) next to the event line. the VBE should open and the cursor should be inside the event. Doing that has always established a link for me.

    Check if the button is enabled too. If it's a standard grey one, you never know if it's disabled or not if it has no caption. The only difference I've noticed by being disabled is the caption words...they turn grey.

  3. #3
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    Thanks, I'm not sure if it was because I established a link or because I saved the DB, but it started working. However, it did need an "http://"

    Now I'm trying to figure out how to pass a form variable into that url...
    i.e. "http://www.address.com/?q=" & formfieldvalue

  4. #4
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    Seems to be something as simple as formname!fieldname ... I think. However, I need something like "Form Name"!"Field Name" but that doesn't work.

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I only know one website that uses that "q" for their search box name. Goooooooooooogle!

  6. #6
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    lol! No, I'm not planning on using it for google, that was just an example, what I need to do is a 'bit' more complicated, but not much. If I can figure out how to pull the string data from the form field, I'll be fine. I'm getting closer. But I think I might need to define it as a string or something... not sure. For now I have :

    Private Sub FindPhone_Click()
    Application.FollowHyperlink "http://www.google.ca" & Forms_ContactandVolunteers.HouseNumber
    End Sub

    But it gives runtime '424' object required.

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    housenumber? remember you can't combine data types and expect the program to smile at you...

    Code:
    "http://www.google.ca" & cstr(forms("ContactandVolunteers").controls("HouseNumber"))

  8. #8
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    The 'housenumber' column is actually stored with a string value.

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by esoikie View Post
    The 'housenumber' column is actually stored with a string value.
    oopsie!

  10. #10
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    The 'housenumber' column is actually stored with a string value.

    Code:
    Private Sub FindPhone_Click()
    Dim strNum As String
    Dim strStr As String
    strNum = Forms_ContactandVolunteer!HouseNumber
    strStr = Forms_ContactandVolunteer!StreetName
    Application.FollowHyperlink "http://www.google.ca/"
    End Sub
    this is what I'm NOW at.... but the strNum = line highlights yellow. I THINK it's having a hard time locating my field.

  11. #11
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by esoikie View Post
    but the strNum = line highlights yellow.
    look at my last post. 99.9% bet the syntax is wrong. use the one in the last post. cstr() is not necessary.

  12. #12
    esoikie is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    7
    Actually, I was right about not finding the field on the form. Once I found me.formfieldname function everything worked out fine.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Button on the form
    By Evgeny in forum Forms
    Replies: 6
    Last Post: 04-29-2010, 12:06 AM
  2. Replies: 1
    Last Post: 03-03-2010, 07:29 PM
  3. Adding VB code on a embedded coding for a button
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-20-2010, 12:25 PM
  4. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM
  5. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums