Results 1 to 9 of 9
  1. #1
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60

    Trying to click a button in vba

    How can go to another form, click a button from that form, and then select option button all using vba?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  3. #3
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60
    What I'm trying to do is click a button. For an example, i open a form, enter a beg. and ending date. When I click the OK button, I want the code to go and click the Report button and select an option button that is below the Report button.

  4. #4
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60
    I tried the following:

    Form1.setfocus
    [forms]![form1].[ReportBtn].setfocus
    'need to select the option button

  5. #5
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60
    Private Sub StartGather_Click()
    On Error Goto Err_StartGather_Click

    Dim stDocName as String

    Form1.setfocus
    [forms]![form1].[ReportBtn].setfocus

    DoCmd.GoToControl "Option103"

    [Forms]![Form1]![Text77].value = #4/20/2011#

    Sendkey Enterkey, True
    DoCmd.Hourglass True

    stDocName = "GatherData2.start"
    DoCmd.RunMacro stDocName
    ' This will run for up to 1 hour
    DoCmd.Hourglass False

    Exit_StartGather_Click:
    Exit Sub

    Err_StartGather_Click:
    MsgBox Err.Description
    DoCmd.Hourglass False
    Resume Exit_StartGather_Click

    End Sub

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    hey bud, you CANNOT 'click' a button in access via code. However, you CAN run procedures behind buttons by simply calling them using the CALL statement. you can call subs and functions both.

    access is not like the DOM, where you can use ".click" to manipulate objects on a web page.

  7. #7
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60
    Thanks, I didn't you could. I've never done it before. I started going in another direction per this project.

  8. #8
    boywonder is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2010
    Location
    Memphis, TN
    Posts
    60
    I was able to get the focus to the button, but could not do a Sendkeys EnterKey to click the button.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    If, what you want to accomplish is to Open a Report with some parameters, you may find this tutorial "Dynamic Reports" helpful. You create a dialog type form and thenhave code to open a Report.
    http://www.fontstuff.com/access/acctut19.htm

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

Similar Threads

  1. Click a Button to Run Word Mail Merge...
    By nchesebro in forum Programming
    Replies: 6
    Last Post: 03-09-2011, 01:41 PM
  2. +1 on button click
    By 10 Gauge in forum Forms
    Replies: 4
    Last Post: 02-14-2011, 06:51 AM
  3. Command button click event
    By R_jang in forum Programming
    Replies: 10
    Last Post: 10-29-2010, 10:13 PM
  4. Increment a value on button click
    By michaeljohnh in forum Programming
    Replies: 9
    Last Post: 08-25-2010, 10:01 AM
  5. On Click Event For Button On Form
    By Desstro in forum Forms
    Replies: 3
    Last Post: 08-09-2010, 02:36 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