Page 3 of 3 FirstFirst 123
Results 31 to 37 of 37
  1. #31
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    I entered all of the information as instructed however when i tested it out by trying to login, i got an error stating "Compile error: variable not defined" with the line

    Code:
    StrSQL = "INSERT INTO Users (ID, User_Name, EMail, User_Type, Date_Worked, Strt_Time) "
    highlighted but the line
    Code:
    Private Sub Login_Click()
    in yellow.

    Below this line I entered the two lines of code you asked for,
    Code:
    Me.ID.SetFocus
    intID_Public = Me.ID
    I'm guessing I got lost when you said something about
    Identify what event will cause the End_Time to be written to the Users Table.

  2. #32
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Just for now . . .

    Put a command button on your Login Form and call it cmdUpdate.

    Then put the code that I gave you behind that - so it looks like this:

    Code:
     
    Private Sub cmdUpdate_Click()
    
    Dim StrSQL As String
    
    StrSQL = "Update Users Set End_Time = #" & Now() & "# Where ID = " _
        & intID_Public & ";"
    
    'MsgBox StrSQL
    
    DoCmd.RunSQL StrSQL
    
    End Sub
    See if that works.

  3. #33
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    I did as asked and as far as I know, the cmdUpdate is working how it should. However my Login button won't add any information into the table.

  4. #34
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    The way the form is set up is not ideal.

    It is real picky about what steps you have to take in order to allow a record to be added.

    This is because the Form is designed by Access to be a self-driven data-entry Form.
    In a self-driven form - you enter data - and then - when you move to another record, Access does the inserting of the data into the Table for you.

    BUT we are using the Login button to insert data because that is what you originally asked for.

    So there's a little 'conflict of interest'.

    The code behind Login is inserting data into the Table - as you requested . . .
    BUT depending on what you click -
    Access will ALSO try and add same the same record that is on the screen to the Table.

    That leads to a problem because you have already clicked the Login button and added the record with the current ID that is on the screen [in the ID text box] into the Table.

    Since ID is a Primary key - you cannot insert the same ID into the Table twice.

    Isn't it FUN????

    Once you start making stuff happen with code - you have to deal with eventualities and make sure that your users are not left with the same problems that you are having.

    You just have to consider everything that can possibly go wrong and then make sure you prevent it.

  5. #35
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    so let me get this straight. The entire code that is entering the information that is in the form is what is messing up right now, because my button and the form are both trying to populate the fields I had asked. If this is the case, then couldn't I simply take away those bits of code, having the user enter their time, however still have the logout button for the user to click, entering that now() time into the end_time field? This is all so very very confusing.

  6. #36
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Yes.

    Your Login button is Inserting a row of data [including the ID].

    As long as that same record is on the Form, if you try & leave that record - Access will try & save it to the Table - because that is how the Form is set up.

    If you select any of the fields on the Form and look at the Control Source property [Data Tab in the Property Sheet] - you will see that the Control Source is a field in your Users Table. This means that the fields on your Form are bound to those fields in the Table.

    This works really well usually.

    The thing is - when you need to do something more than what Access will do automatically for you - then you have to take on the whole responsibility for managing how data is entered, deleted, updated etc.

    Most times You will have your own buttons on the Form to do all these things - and each of the buttons will have the exact code that you want in it so that users can only do what you design the Form to do - and nothing more. Eg: if you have an Exit button on the Form - you might put a MsgBox in there saying that the current record will NOT be saved . . . or asking if the user WANTS to save . . .

    You get a lot more control - but you lose the point & click ease of use.

    I think you will get to appreciate the control that programming stuff gives you - but you will also appreciate the ease that comes with using built-in Access functionality.

  7. #37
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    would it be possible, or even just look good in the sense of me wanting this to simply record the date and time, if, instead of having a log-in button, simply have the user click the "next" button on the lower left side. Then, when they are done, click the log-out function on the current form to insert the now() into the End_Time field? I think this would lose the certain dynamics that come with a "login form" but would be the only way that I know of working WITH Access to get my desired outcome, a form which records a persons date, time-in, and time-out. What do you think?

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2011, 11:35 PM
  2. Replies: 2
    Last Post: 10-27-2009, 07:09 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