Results 1 to 14 of 14
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    how to sync forms subforms to combobox.value onLoad

    Hi, I have a main form with subforms, the main form has a combobox and in the form onload event I set its value by

    Me.cmbMempSpecies = Me.cmbMempSpecies.Column(0, 0)

    The problem is other fields on my form and subforms are only updated after I select a value from this combobox
    How do I update the forms and subforms to the combobox value onLoad.

    Thanks for any help
    David

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is there code that runs in the after update event? If so, you need to run it from the load event too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul, Thanks for your reply.
    I'm a little confused, after you asked about after update I checked the combobox after update event and found a macro

    Code:
    SearchForRecord
         Object Type
          Object Name
          Record:  First
       Where Condition =="[SpeciesID] = " & Str(Nz([Screen].[ActiveControl],0))
    No idea what this means - maybe you can enlighten me.

    In the OnLoad event I already have vba code and don't know how to add this macro as well - what do you suggest?

    Thanks
    David

  4. #4
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    I found the "convert Forms Macros to Visual Basic", and and after running placed :



    Call cmbMempSpecies_AfterUpdate

    into the Form_Load.

    but I get an error:

    "The expression you entered requires the controls to be in the active window"

    Any ideas how to solve this?

    Thanks
    David

  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,521
    I would just copy the code produced by the conversion and add it to your load event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    After copying I still get the same message!

    Here's the form onLoad code:
    Code:
    Private Sub Form_Load()
         Me.cmbMempSpecies = Me.cmbMempSpecies.Column(0, 0)
         Me.TabCtl0.Value = 0
         TabCtl0_Change
    ' Copied code from cmbMempSpecies_AfterUpdate below - after conversion
    ' ====================================================
    On Error GoTo cmbMempSpecies_AfterUpdate_Err
    
    
        DoCmd.SearchForRecord , "", acFirst, "[SpeciesID] = " & Str(Nz(Screen.ActiveControl, 0))
    
    
    
    
    cmbMempSpecies_AfterUpdate_Exit:
        Exit Sub
    
    
    cmbMempSpecies_AfterUpdate_Err:
        MsgBox Error$
        Resume cmbMempSpecies_AfterUpdate_Exit
    End Sub

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, there probably is no active control yet. Change that to specify the combo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul,
    Excuse my ignorance, tried: Screen.ActiveControl = Me.cmbMempSpecies

    getting run time error 2474 "the expression you entered requires the control to be in the active window".

    Could you give me the code I need.

    It appears that in the Form_Load where I'm trying to run this there are no active forms or controls

    Thanks
    David
    Last edited by mdavid; 11-05-2017 at 02:23 AM.

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Code:
    DoCmd.SearchForRecord , "", acFirst, "[SpeciesID] = " & Str(Nz(Screen.ActiveControl, 0))
    I don't know why macros love this sort of syntax. Just specify your control directly instead of that weird indirect method:
    Code:
    DoCmd.SearchForRecord , "", acFirst, "[SpeciesID] = " & cmbMempSpecies

  10. #10
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Dave, Much appreciated, unbelievable how much time and energy I've wasted on this, and the solution's so simple.

    At least now I know how to convert macros - don't click "Convert Form's Macros to Visual Basic"

    Marked as Solved
    Thanks
    David

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI, that's what I meant by specifying the combo. It's okay to use that conversion method, you just have to realize that the resulting code may need tweaking.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul, Appreciate your help, problem is I need to be spoon fed - 'cause I didn't know how to "specify the combo".

    Thanks
    David

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, since you were doing it above I assumed you did.

    Me.cmbMempSpecies = Me.cmbMempSpecies.Column(0, 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul, I did have that line, but the problems continued - as I said in reply #8.

    This what worked in the end:

    Code:
    Private Sub Form_Load()
         Dim ctrl As ComboBox
         Dim frm As Form
         Me.cmbMempSpecies = Me.cmbMempSpecies.Column(0, 0)
         Me.TabCtl0.Value = 0
         TabCtl0_Change
         Me.Refresh
    '  Following line sets all forms/subforms to the first record in the Combo list
        DoCmd.SearchForRecord , "", acFirst, "[SpeciesID] = " & cmbMempSpecies
    End Sub
    Thanks
    David

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

Similar Threads

  1. Sync two forms....
    By dennissanford in forum Forms
    Replies: 3
    Last Post: 08-31-2013, 11:33 PM
  2. Sync Sub Forms on Navigation Form
    By moirakalichman in forum Programming
    Replies: 15
    Last Post: 03-03-2013, 02:01 PM
  3. Replies: 5
    Last Post: 01-16-2013, 03:48 PM
  4. Custom combobox sync solution
    By rhewitt in forum Forms
    Replies: 5
    Last Post: 09-05-2012, 05:20 AM
  5. Replies: 3
    Last Post: 08-29-2012, 02:42 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