Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Trying to requery a listbox

    After I log in, my main menu appears. On the main menu, I have a list box (lstTrainingScheduled). Right now, it just appears empty even though it should have information in it. If I click on it and press F9, it will requery and the information appears. How would I write a code so that it will do this automatically?

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Shouldn't have to press F9 (recalculate) or F5 (requery).
    Hard to know what is going on without seeing it...... Care to post your dB??

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Too much real information in my db to post

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe:
    make a copy of the dB,
    delete the data,
    make up some test data (a few records that illustrate the problem),
    do a "Compact & Repair",
    Zip it,
    then Post it?


    Or just the part that is causing the problem? (again with a few test records)...

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Here is the database with very few records, It opens to a login. Username: Test / Password: 12345. I only have one name record in it. It is Employee 18. If that is a default in the Main Menu, It opens the subform right away correctly. By using the login, it will not bring in the information for the subform. I changed the list box to a subform.
    Attached Files Attached Files

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    In the AfterUpdate event of the password field onfrmLogin add a call to requery your listbox.

    Cheers,
    Vlad

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    The sub form will load before the main form.
    This would be better achieved using the OpenArgs property. Pass the logged in EmpID into the Main menu and the set things OnLoad from there.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That's what I'm trying to do. I thought it was supposed to be in the On Activate. This is the code I used. It didn't work. What would be a better way?
    Forms!frmMainMenu!frmTrainingEmployeeScheduled.Set Focus
    Requery

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    See the attached.
    Police Management System v.2.1.1 - Copy.zip

    See how to pass employee id (X) to the main menu form.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Because of how I've structured the database, this menu will be closed and opened several times. The login form will only be used once. Passing the information from there won't work after the main menu has been closed and then opened again. I'm still thinking that a requery of the subform will work if I can get it to requery by itself once the main menu opens. I just don't know how to do that.

  11. #11
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Look at the code - I've added a requery to the on current event.
    However if your Main Menu is unbound - there won't be a record change to fire that event.

    You would need to find another way of doing that, possibly use a combo to select the user you want and requery on the AfterUpdate event of the combo?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That worked in the database you add the code to. When I tried it in mine, it gave me an error. I changed FirstName to UserName. I wanted the username to be displayed.Click image for larger version. 

Name:	Error.jpg 
Views:	20 
Size:	83.8 KB 
ID:	32184 After looking at your code, it looks like the information is passed just the way I wanted it to. For some reason, it gave me this error.

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Have you tried this and it didn't work:

    Private Sub Command0_Click()
    If IsNull(txtUsername) Then
    MsgBox "Invalid username"
    Exit Sub
    End If
    If IsNull(txtPassword) Then
    MsgBox "Invalid Password"
    Exit Sub
    End If
    Dim X As Long
    X = Nz(DLookup("EmployeesID", "qryEmployeesCurrent", "Username='" & txtUsername & "' AND Password='" & txtPassword & "'"))

    If X > 0 Then
    ' We have a valid user
    DoCmd.OpenForm "frmMainMenu"
    Forms!frmMainMenu!txtUserID = X
    Forms!frmMainMenu!txtUsername = txtUsername
    Form_frmMainMenu.Scheduled_Training.Requery 'vc Jan16, 2018
    DoCmd.Close acForm, "frmLogin"
    Else
    MsgBox "invalid Login"
    End If


    End Sub

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That worked great for the initial login. Unfortunately, when I move off the form and then back on it, it's not doing the requery. I still need a way for it to requery when the form is call up.

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    As long as the userid is still there just add me.Scheduled_Training.Requery to the OnActivate event of the main menu form

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Requery Listbox with the following code
    By UTLee in forum Programming
    Replies: 9
    Last Post: 09-05-2014, 08:37 AM
  2. Requery Does Not Update Listbox Row Source
    By szucker1 in forum Forms
    Replies: 7
    Last Post: 02-11-2014, 08:58 AM
  3. Requery ListBox on Mainform from Subform
    By Ruegen in forum Forms
    Replies: 11
    Last Post: 10-29-2013, 09:27 PM
  4. Replies: 19
    Last Post: 11-01-2012, 08:03 AM
  5. after DAO update, listbox.requery not refreshing
    By EuniceH in forum Programming
    Replies: 2
    Last Post: 10-21-2011, 04:16 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