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

    Once the form closes, the information goes too.

  2. #17
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I see... No problem, you need to store the original login (I assume that this is a split database and each user is using their own front-end) in a local front-end table. Then in the OnLoad event of the main menu form simply do a dlookup to populate the UserID (and the user name if you wish but that is not really needed for the subform). That way you don't have to do the requery as the id will be correctly populated. I believe I saw a systemsettings table, just add the UserID and username fields in there.

  3. #18
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I kinda like the idea of requerying the subform better. Minty had a great idea, but for some reason it won't transfer to my database. Need to work on it more. Thanks.

  4. #19
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    If you don't save the login info in a local table you will not be able to do what you want as the UserId will not be populated when you reopen the main form (unless you open it via the login form again). If your database is not split and you use it in multiuser environment (not recommended but doable) you can simply add a new field to your employees table to hold the Windows login and use that in the load event of the form (dlookup("[EmployeesID]","[tblEmployees]","[WindowsLogin]" =""" & Environ("UserName") & """") assuming users don't share computers.

    Good luck!
    Vlad
    .

  5. #20
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Code:
    Private Sub txtTextBox_AfterUpdate()
    
    
    Me![txtTextBox].Requery
    End Sub

  6. #21
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    To requery when you navigate away from form and back to it use.

    Code:
    Private Sub Form_Click()
    
        Me![txtTextBox].Requery
    
    End Sub

  7. #22
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Some other options I know that works but since I do not know how your stuff is setup I can only give you options.

    Code:
    Private Sub Detail_Click()
    On Error Resume Next
    
        'If an incomplete data entry on form is not removed before clicking outside subform area access crashes without "On Error Resume Next".
        Me.Refresh
    
    End Sub
    Code:
    Private Sub TabControl_Click()
    
        Me.Refresh
    
    End Sub

  8. #23
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    As Gicu said about adding text box fields to your login form and make visible = No and make the text box field = Locked. Then add this to your login form VBA btnLogin_Click() event:

    Code:
    Me.txtTextBox.Value = DLookup("What", "tblWhere", "[Username] = '" & Me.txtUsername & "'")
    Repeat the aforementioned for everything on your forms that call on the login form text boxes for their values. Otherwise a lot of unnecessary network traffic will occur every time something routine is queried. You should query the database once for routine information used throughout your forms, then from there on those values are stored on a form for local reference.

    An example of using local call instead of query database every time is [Forms]![frmLogin]![txtTextBox]

    I personally would NOT do a Windows login call. I would have a separate username and password for the database. Moreover, I would not call anything into memory (i.e. TempVars) from a digital forensics and malicious extraction point of view. Just my two cents!

  9. #24
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I've looked at the example dB and see many things that should be fixed (IMHO).

    1) The dB should be split into a FE and a BE. Each user should have a COPY of the FE on their computer. Multiple users in one non-split dB, sooner or later, will be corrupted. Not a matter of IF.... just a matter of WHEN.

    2) EVERY module should have the TOP two lines of
    Code:
    Option Compare Database
    Option Explicit
    3) You should take the time to properly rename objects, not blindly accept what MS names them.
    Code:
    '------------------------------------------------------------
    ' Command22_Click
    '
    '------------------------------------------------------------
    Private Sub Command22_Click()
        On Error GoTo Command22_Click_Err
    
        DoCmd.Quit acPrompt
    
    Command22_Click_Exit:
        Exit Sub
    
    Command22_Click_Err:
        MsgBox Error$
        Resume Command22_Click_Exit
    
    End Sub
    
    Private Sub Command48_Click()
        DoCmd.OpenForm "frmTrainingEmployeeListing", acNormal, "", "[EmployeesID]=" & txtUserID, , acNormal
    End Sub
    
    Private Sub Command58_Click()
        DoCmd.OpenForm "frmTrainingEmployeeScheduled", acNormal, "", "[EmployeesID]=" & txtUserID, , acNormal
    End Sub
    
    Private Sub Command66_Click()
        DoCmd.OpenForm "frmTrainingUpcomingClasses"
    End Sub
    What do these subs do???

    How about now???
    Code:
    Private Sub cmdExit_Click()
        On Error GoTo cmdExit_Click_Err
    
        DoCmd.Quit acPrompt
    
    cmdExit_Click_Exit:
        Exit Sub
    
    cmdExit_Click_Err:
        MsgBox Error$
        Resume cmdExit_Click_Exit
    
    End Sub
    
    Private Sub btnTrainingList_Click()
        DoCmd.OpenForm "frmTrainingEmployeeListing", acNormal, "", "[EmployeesID]=" & txtUserID, , acNormal
    End Sub
    
    Private Sub btnTrainingSched_Click()
        DoCmd.OpenForm "frmTrainingEmployeeScheduled", acNormal, "", "[EmployeesID]=" & txtUserID, , acNormal
    End Sub
    
    Private Sub btnTrainingClsses_Click()
        DoCmd.OpenForm "frmTrainingUpcomingClasses"
    End Sub

    In the button "Command22_Click", you have
    Code:
        DoCmd.Quit acPrompt
    The "acPrompt" argument is only for CHANGES to the form design. It does NOT prompt to save data.
    This is the code I use:
    Code:
    Private Sub cmdExit_Click()
       If MsgBox("Exit Access?", vbYesNo, "Are You Sure?") = vbYes Then
          DoCmd.Quit
       End If
    End Sub
    4) In form "frmLogin", I would do as suggested and add a hidden text box to hold the employeeID. If the username and password match, fill in the employee id text box, then hide the form (instead of closing the form).
    Code:
    Private Sub Command0_Click()  '<< RENAME
        Dim X As Long
    
        If IsNull(Me.txtUsername) Then
            MsgBox "Invalid username"
            Exit Sub
        End If
        If IsNull(Me.txtPassword) Then
            MsgBox "Invalid Password"
            Exit Sub
        End If
    
        X = Nz(DLookup("EmployeesID", "qryEmployeesCurrent", "Username='" & Me.txtUsername & "' AND Password='" & Me.txtPassword & "'"))
    
        If X > 0 Then
            ' We have a valid user
            Me.tbEmpID = x
            DoCmd.OpenForm "frmMainMenu"
            Forms!frmLogin.Visible = False
          '  Forms!frmMainMenu!txtUserID = X
          '  Forms!frmMainMenu!txtUsername = Me.txtUsername
          '  DoCmd.Close acForm, "frmLogin"
        Else
            MsgBox "invalid Login"
        End If
    
    End Sub
    Then you can have the info available for any form.......

Page 2 of 2 FirstFirst 12
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