Results 1 to 15 of 15
  1. #1
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8

    Refresh Table Data Based On ComboBox

    Cross Post Links
    https://www.mrexcel.com/board/threads/refresh-table-data-based-on-combobox.1178079/
    https://www.access-programmers.co.uk/forums/threads/refresh-table-data-based-on-combobox.318905/
    https://www.accessforums.net/showthread.php?t=84133&p=480705#post480705

    I am asking this question on multiple forums as I'm not sure what is the best forum to get assistance with my question. It will also hopefully see assistance from different users which should give different solutions (multiple learning opportunities).


    Hi,

    Sorry in advance if this doesn't make sense!

    I am hoping someone can assist, I am currently building a Microsoft Access Database for my workplace to keep track of employees and their movements (e.g. Team Changes). I am trying to create an Employee Details Form like in the Student \ Time Card Microsoft Access Templates where I use a combo box to select from a list and once an employee is selected their details load in the fields on the form. I have tried importing this form and updating the source to my query but am unable to get the Embedded Macro to work. I am wondering if someone can please either explain how the Combo Box on the Templates are setup\work or alternatively what code (either Macro or Embedded Macro) could I use from scratch to have my form do the same.

    Thanks in advance,
    t0ny84

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Can you post a copy of your db
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Hey Bob,

    Here is a trimmed down version including the Table, Query and Form (The fields are a bit chopped up as it wouldn't allow me to upload a file over 500kb).

    Thanks in advance for any and all assistance.

    t0ny84
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,935
    Well thank you for posting the cross post links.
    Might want to alert the other sites as well though?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Quote Originally Posted by Welshgasman View Post
    Well thank you for posting the cross post links.
    Might want to alert the other sites as well though?
    Hey Welshgasman can confirm I did this when I created the new posts on each relevant forum.

  6. #6
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Hey Bob,

    Here is a trimmed down version including the Table, Query and Form (The fields are a bit chopped up as it wouldn't allow me to upload a file over 500kb).

    Thanks in advance for any and all assistance.

    t0ny84
    Attached Files Attached Files
    Last edited by t0ny84; 08-03-2021 at 05:41 AM. Reason: Getting Error When Posting

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,935
    Yes, just seen that on AWF ��
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    t0ny84

    I think the attached db does what you require but it uses VBA rather than Macros. Hope this helps
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Hey Bob,

    Thank you so much for your prompt assistance, this looks to work perfectly for this situation. Having the code also I should be able to customise for other parts of this project.

    A very big thank you again!

    t0ny84

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by t0ny84 View Post
    Hey Bob,

    Thank you so much for your prompt assistance, this looks to work perfectly for this situation. Having the code also I should be able to customise for other parts of this project.

    A very big thank you again!

    t0ny84
    I'm glad that you found it of use.
    I would encourage you to use code rather than macros.
    Any macros that you have in a form/report can be converted onto code by Access. There's a command on the design ribbon.

  11. #11
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Quote Originally Posted by Bob Fitz View Post
    I'm glad that you found it of use.
    I would encourage you to use code rather than macros.
    Any macros that you have in a form/report can be converted onto code by Access. There's a command on the design ribbon.
    Hey Bob, can you confirm in sub Form_Load() the line
    DoCmd.GoToRecord , "", acNewRec

    should take the form to a new record (open blank?)?

    If so do you know what would be stopping it from not working, when I run your version it always takes me to the first employee in the list.

  12. #12
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    I believe I might have solved it:

    Original Private Sub Form_Load
    Code:
    Private Sub Form_Load()
    
    
    On Error GoTo Form_Load_Err
    
    
        If (IsNull(OpenArgs)) Then
            Exit Sub
        End If
     DoCmd.GoToRecord , "", acNewRec
    Edited Private Sub Form_Load
    Code:
    Private Sub Form_Load()
    
    
    DoCmd.GoToRecord , "", acNewRec
    ' Commented out below DoCmd and added it here.
    
    
    On Error GoTo Form_Load_Err
    
    
        If (IsNull(OpenArgs)) Then
            Exit Sub
        End If
    ' DoCmd.GoToRecord , "", acNewRec <- Commented this line out.

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    t0ny84

    The code in the form's Load event is original code as you posted.
    The first three lines ask if the form's OpenArgs property is null and if that is true the code exits the sub.
    The following line, which moves to a new record, is only reached and run IF the form's OpenArgs property has some value.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    t0ny84 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2021
    Posts
    8
    Hi Bob,

    With
    Code:
    DoCmd.GoToRecord , "", acNewRec
    after the first three lines it always loads the form with the first available record where as with it before the first three lines it opens blank on a new record. Would I be correct in assuming that my method makes these lines of code redundant?



  15. #15
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by t0ny84 View Post
    Hi Bob,

    .....where as with it before the first three lines it opens blank on a new record......


    That could only be true it it were opened from some event code or macro that supplied a value to the form's OpenArgs property.
    If the form is only ever opened directly from the Navigation pane then none of the code after the first three lines will ever run.
    If all you want is for the form to always open at a new record then the only code you require is:
    Code:
    DoCmd.GoToRecord , "", acNewRec
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 4
    Last Post: 05-22-2018, 10:35 AM
  2. Replies: 2
    Last Post: 02-21-2018, 01:32 AM
  3. Replies: 4
    Last Post: 11-07-2014, 04:25 PM
  4. Replies: 1
    Last Post: 05-24-2014, 09:08 AM
  5. Replies: 4
    Last Post: 02-09-2012, 03:03 AM

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