Results 1 to 5 of 5
  1. #1
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Running a button from a buttion in a different form.

    Greetings, im having a bit of issues coding this correctly. I keep getting variable not defined error. The theory is I click on a button and if the (status) field = "NEW", then it opens my search form (frmFileSearch), sets THAT status field (cbostatus) to "NEW" and runs the search button (cmdFilter_Click) to populate the results.

    This is the code I got so far.



    Code:
    Private Sub Command2_Click()
    If Status = "NEW" Then
    DoCmd.OpenForm "frmFileSearch", acNormal
    frmFileSearch.cboStatus.Value = "NEW"
    frmFileSearch.cmdFilter_Click = True
    frmFileSearch.cmdFilter_Click = vbClick
    End If
    End Sub
    im sure im missing something basic! Thank you in advance

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    If they are bound forms why not just requery the form after populating the status with 'new'

    Is there some other code running with your click event of the secondary form? If so you create a function and call the function from both your click event and when you open the form.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The command button would have to be public rather than private, and the code would look like:

    Forms!frmFileSearch.cmdFilter_Click
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    That worked thank you, does changing it to public affect anything else in the long run or should I be okay?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The only affect I can imagine is if you had a button on another form with the same name. An alternative as rpeare suggested is a function you call from both events.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 05-06-2013, 12:56 PM
  2. Show buttion in form if count of qry >0
    By tcheck in forum Access
    Replies: 1
    Last Post: 03-05-2013, 03:30 PM
  3. Running a module from a button in a form
    By sardamil in forum Modules
    Replies: 3
    Last Post: 05-01-2012, 10:59 PM
  4. Running exe's or Powershell from an Access form button
    By HoustonIT in forum Programming
    Replies: 7
    Last Post: 04-14-2011, 02:57 PM
  5. Replies: 1
    Last Post: 04-06-2009, 12:05 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