Page 1 of 4 1234 LastLast
Results 1 to 15 of 53
  1. #1
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41

    Condition issues

    If my code has the following



    Private Sub Timein_Click()
    Dim Intime

    Intime = 1
    End Sub


    and I follow it, after adding information, with this submit onclick

    Private Sub Submit_Click()
    If Intime = 1 Then
    '[Souls] = [Souls] + 1
    Me![Check In] = Now()
    Else
    If Outtime = 1 Then
    '[Souls] = [Souls] - 1
    Me![Check Out] = Now()
    End If
    End If
    RunCommand acCmdSaveRecord
    Me.Requery
    End Sub

    It's not recognizing the fact that Intime is = 1 therefore not putting NOW() into my Check In field. What am I missing

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Variable declared within a procedure has a life only within that procedure - no other procedure can see it. You must declare Intime in module header. If you do this in a general module then any procedure in the db can see the variable. Often referred to as a 'global' variable. Be aware that these variables lose their value if code execution is interrupted. TempVars are another type of variable and they do not lose value if code execution is interrupted.


    Option Compare Database
    Option Explicit
    Public Intime AS Integer
    ________________________________

    Private Sub Timein_Click()
    Intime = 1
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bigot is offline Advanced...ish
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    37
    June7's answer would work, but I think you're going about this wrong. However, I'm not quite sure what you're doing.

    Assuming you're doing a timesheet thing, and assuming you want 1 button for check-in and check-out, this would be its code:
    Code:
        If IsNull( [Check In] ) Then
             [Check In] = Now()
        Else
                [Check Out] = Now()
        End If
        Form.Requery
    This would be all you need if your form filters out all entries where neither of [Check In] and [Check Out] are null, and new rows are allowed. If it does not filter this, just add an ElseIf that checks if both [Check In] and [Check Out] are filled, in which case it would add a new row.

    I'm not sure if I articulated that well enough. If you explain in more detail what your objective is, I think I can help further.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    fspata,
    In addition to the comments by others, I suggest you use code tags to surround your vba. It makes things easier to read, in my view.
    Highlight the vba code, then click on the # button that is viewable just above the post/edit box.


    Also, I agree with bigot that what you are really trying to accomplish is not clear.
    Good luck.

  5. #5
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41
    Thank you for the responses and I apologize for the delay in getting back. I work 2nd shift, which is such a pain, so I get back on here whenever I can. Just to clarify my form in a nutshell. People are either checking in or out of our building using the Check In or Out button as their choice. Either button is supposed to set an 'Intime' or 'Outtime' condition, which after they fill out the rest of the form with their information, on Check In only, after they hit submit, it would enter NOW() into my Check In field in the Initial table. Choosing Check Out, which I really haven't worked on due to the fact of getting Check In to work properly first, I guess I will want them to scan their ID after hitting the Check Out, which would update their latest Check In record with the Check Out time in the Check Out field which is in the same table. Ok, how many are confused, raise your hands lol? I would post my db with tables but things are proprietary. TIA

  6. #6
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41
    Code:
    Option Compare Database
    Option Explicit
    Public Intime AS Integer
    ________________________________
    
    Private Sub Timein_Click()
    Intime = 1
    End Sub
    So all of this would be at the top of the General coding area?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes, as indicated in post.

    Check In/Out is fairly common db discussed in threads. What is proprietary? We don't need real data. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41

    Test Db

    Here is the Db.
    Attached Files Attached Files

  9. #9
    bigot is offline Advanced...ish
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    37
    Quote Originally Posted by fspata View Post
    I will want them to scan their ID after hitting the Check Out, which would update their latest Check In record with the Check Out time in the Check Out field which is in the same table
    AWW HELL YEAH. I've wanted to do scanning to check-in/out for a while, I'll just live my dream through you. So I'm just gonna fly through what you should do, I suggest doing it in a new database altogether (that you're able to share with us so we can more easily help you should you have more problems).

    First, make the check-in/out table:
    IDCheckInOut (primary key)
    employeeID (foreign key)
    timeCheckIn
    timeCheckOut

    Your Employee table should look something like:
    IDEmployee (PK)
    ScanningCode (this is the code from the ID they scan)
    ....

    Then make a form for people to scan their ID, controls:
    txtIDInput (textbox, and should be your only tabstop)
    cmdSubmit (button) - set this button to default (clicked when "enter" is pressed) because as far as I know, scanners emulate "enter" after finishing scanning the barcode. Also set tabstop on this to false.



    Now the fun begins. This code is untested, but should give you a good idea of how to do exactly what you want:
    Click event for cmdSubmit:
    Code:
    'this will get the employee's ID from their scanned code. I'm assuming  no invalid IDs will be scanned here. You should build that in though
    Dim empID as Integer
    empID = DLast( "IDEmployee", "tblEmployees", "ScanningCode=" & txtIDInput
    
    
    'this will look for a timesheet entry where the employee is checked in but not checked out - returns NULL if it can't find it (which means the employee is not checked in)
    dim checkInOutID as integer
    checkInOutID = DLast( "IDCheckInOut", "tblCheckInOut", "employeeID=" & empID &  " AND timeCheckIn IS NOT NULL AND timeCheckOut IS NULL" )
    
    
    
    if isnull(checkInOutID) then
      'employee is not checked in, add a check in row!
    
      ' it's probably a good idea to re-write this to use recordsets and .AddNew rather than what i have below, but this will work.
      ' this code assumes timeCheckOut allows (and defaults to) null
      docmd.setwarnings false
      docmd.runsql "INSERT INTO tblCheckInOut ( employeeID, timeCheckIn ) VALUES ( " & empID & ", " & cdbl( now() ) & " ) "
      docmd.setwarnings true
    
    else
      'employee is checked in, check them out!
      
      ' this should be obvious - update the record (where the employee checked in but not out) to check out now.
      docmd.setwarnings false
      docmd.runsql "UPDATE tblCheckInOut SET timeCheckOut=" & cdbl(now()) & " WHERE IDCheckInOut=" & IDCheckInOut
      docmd.setwarnings true
    endif
    
    'this may be unnecessary:
    txtIDInput.setFocus

    Once you've done that, I'd fancy it up a bit with a subform that shows their recent check-in/out times, maybe stay on the screen for like 20 seconds then go away (so the next employee can't see the previous employee's time), etc.

    Keep us posted on how this project goes. I'm very excited for you.

  10. #10
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41
    Bigot, I appreciate the advice on starting in a fresh Db but I am under some time restraints and this one is almost complete after a lot of bumps in the road due to my lack of experience lol! Question on the Check Out button. I have tried getting it to SetFocus on the ID field of the form but its not getting there for some reason. Here is what I am using.

    Code:
    Private Sub Timeout_KeyUp(KeyCode As Integer, Shift As Integer)
        Me![BEMSID].SetFocus
    End Sub

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Are you getting error message?

    I name data controls different from fields bound to, like: tbxID. Then reference the control:

    Me.tbxID.SetFocus
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Use the code example like June7 posted. I believe using the bang will default to the field within the RecordSource, not the Control on the form.
    Me.BEMSID.SetFocus

  13. #13
    bigot is offline Advanced...ish
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    37
    "KeyUp" is referring to keyboard keys. Are you clicking the button with the mouse?

    As I already suggested: you should only do one button for both checking in and out - let Access automatically detect which is needed. You don't want to rely on the users to click the right button.

  14. #14
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41
    Yes on the KeyUp. I am looking at that possibility.

  15. #15
    fspata is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2015
    Posts
    41
    Still not getting there with Me.BEMSID.SetFocus. Should it be put into the On_Click event?

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

Similar Threads

  1. New record condition
    By rosscortb in forum Access
    Replies: 3
    Last Post: 07-06-2015, 07:19 AM
  2. Where Condition
    By NISMOJim in forum Programming
    Replies: 4
    Last Post: 04-09-2014, 11:10 PM
  3. Help with using the AND condition
    By ssturges in forum Access
    Replies: 1
    Last Post: 11-25-2012, 12:36 AM
  4. Like condition for 1 column help pls!
    By stodd in forum Queries
    Replies: 1
    Last Post: 03-14-2010, 01:51 AM
  5. How to use IIF condition
    By nshaikh in forum Queries
    Replies: 4
    Last Post: 09-12-2008, 01:23 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