Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add Record (A2K)

    Good Morning,

    I have a very simple SignIn/SignOut form w/4 bound Controls and 1 unbound.

    Everything as far as coding goes...all is fine....

    However, when I open the form it continues to go to a new record and I don't always want to do that...(depending on the code).....I've checked to verify "Data Entry" = "No"......and it does.

    Below is my code:
    <hr>Option Compare Database
    Option Explicit
    Private Sub cmdIn_Click()
    dTimeIn = Now()
    DoCmd.Close
    End Sub
    Private Sub cmdOut_Click()
    dTimeOut = Now()
    iTCClosed = -1
    DoCmd.Close
    End Sub

    Private Sub Form_Current()
    'Determine if the either dTimeIn or dTimeOut has data...if both have data,
    'move to a new record and assign UserLogin name

    If IsNull([dTimeIn]) Then 'if dTimeIn is empty disable dTimeOut
    cmdOut.Enabled = False
    Else
    cmdOut.Enabled = True
    DoCmd.GoToControl "cmdOut"
    cmdOut.SetFocus
    cmdIn.Enabled = False
    End If

    End Sub

    Private Sub Form_Load()
    If iTCClosed = -1 Then
    DoCmd.GoToRecord acForm, "fTimeCard", acNewRec
    UserLogin = GetUser
    pkEmployeeID = DLookup("[pkEmployeeID]", "tEmployees", "[tUserLogin] ='" & Forms!fTimeCard!UserLogin & "'")
    dDate = Date
    End If

    If iTCClosed = 0 Then
    DoCmd.GoToRecord acForm, "fTimeCard", acLast
    End If


    End Sub

    Private Sub Form_Open(Cancel As Integer)
    DoCmd.Restore
    End Sub
    <hr>

    Does anyone have any idea why?

    Thanks,

    also....what is the DatePart for short time
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add Record (A2K)

    Last question first: DatePart returns only one part (month, day, hour, ...) of a tate/time. To get short time, you can use the Format function: Format([DateField],"Short Time")

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add Record (A2K)

    What is iTCClosed? A field in the record source of the form? Or a global variable? Or ...?

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add Record (A2K)

    iTCClosed: a Yes/No field in the table and control on the form. Once both In and Out time are complete, iTCClosed = closed.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add Record (A2K)

    You check the value of iTCClosed in the On Load event of the form. The code will look at the iTCCLosed value of the first record. If this value happens to be True (-1), the code makes the form jump to a new record. That may not be what you want, but I cannot tell you what you do want.

  6. #6
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add Record (A2K)

    Thanks Hans. The peice of information regarding "FIRST", I wasn't aware of.

    What I'm trying to do is:
    Open TimeCard. GetUser() retrieves the user logon. DLookup provides the First and Last Name of the user. 2 buttons, Time In and Time Out (respective text boxes are invisible but updated by the clicking of the either button) and the form closes.

    However, if a user opens the form, the form needs to determine if this should be a new record. A new record is determined by BOTH Time In and Time Out Is Not Null of the LAST record . If TRUE, then NEW RECORD. If Time In Is Not Null but Time Out is, the user is taken to the current record with cmdTimeIn dimmed and cmdTimeOut enabled. The user then clicks cmdTimeOut and the form closes.

    So....now that I understand that the code is looking at the FIRST record, what do I need to do to get it to look at the LAST record?

    Sorry to be a bother and thanks for your help.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add Record (A2K)

    At the beginning of the Form_Load event procedure, insert the line

    RunCommand acCmdRecordsGoToLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •