Results 1 to 12 of 12
  1. #1
    Join Date
    May 2008
    Posts
    4

    Unanswered: Can anyone tell me how to do this?

    Hi,

    I work in an education center and in charge of developing an attendance system. I designed a multiple form as well as bought a barcode scanner.

    My hope is that once I input the Student No. in a certain box at the bottom of the multiple form using the barcode scanner or whatever, the system creates a record with the student no. and its "IN TIME" and when the same input is deteced, the "OUT TIME" is marked. I have designed the basic tables and neccesary fields except that I don't know how to write the VB script to tell it to create a new record to the multiple form with the student no. typed. Do you have any ideas?

    Many Thanks!

  2. #2
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    tbh I never worked with bar code scanner but your requestis simple, when you trigger the scanner it normally shall returns the student code (I don't know what is the procedure for that) so you can use gotorecord method to open a new record and put the data as follow:
    (I assume you have three text boxes for Studend ID as SudentID, In Time as InTime and Out Time as OutTime in your form)
    Code:
    DoCmd.GoToRecord , , acNewRec
    Me.StudentID= ID form scanner
    Me.InTime=Time
    Me.OutTime=Time
    Me.Form.Requery
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  3. #3
    Join Date
    May 2008
    Posts
    4
    Quote Originally Posted by Aran1
    tbh I never worked with bar code scanner but your requestis simple, when you trigger the scanner it normally shall returns the student code (I don't know what is the procedure for that) so you can use gotorecord method to open a new record and put the data as follow:
    (I assume you have three text boxes for Studend ID as SudentID, In Time as InTime and Out Time as OutTime in your form)
    Code:
    DoCmd.GoToRecord , , acNewRec
    Me.StudentID= ID form scanner
    Me.InTime=Time
    Me.OutTime=Time
    Me.Form.Requery
    Really Thanks! But how can I tell it to go to the specific record to set the current time at "OUT TIME" when the same ID is inputed?

  4. #4
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    simple
    Code:
    DoCmd.SearchForRecord , "", acFirst, "[StudentID] = " & ID From scennaer & "'"
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Hmmm.... Which version was SearchForRecord introduced?

    I'd use VBA to set the appropriate value. Once the scanner gets the barcode, the VBA kicks in, and looks for the student number in whatever table you have to record the necessary data (it really helps if you detail this). If the data is not found, create a new record and mark it as IN. If the data does exist and is currently marked as OUT, mark it as IN. If the data exists and is marked as IN, mark it as OUT.

    Then all you have to do is navigate to the correct record.
    Last edited by StarTrekker; 05-21-08 at 08:21.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    I would do your method also but I think for someone who is beginner with VBA SearchForRecord is much easier
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    If it exists in the version they have.... yes... but that only deals with going to the record in the form; it doesn't address the issue of handling the logic, which is what I am trying to introduce... Your code creates a new student and flags them as IN and OUT no matter what. SearchForRecord isn't going to help with the logic!!
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    I don't think we should tell him the logic, he should do it personally as per his requiremets for his db, I just gave him the hint
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  9. #9
    Join Date
    May 2008
    Posts
    4
    Code:
    Private Sub Text101_Enter()
    
    If DLookup("[IN_LESSON]", "Student", "[ID] = [Text101]") = 0 Then
    
    DoCmd.GoToRecord , , acNewRec
    Me.ID = Text101
    Me![in].Value = TIME()
    Me.Form.Requery
    
    Text101.Value = ""
    
    Text101.SetFocus
    
    Else: DoCmd.SearchForRecord , "", acFirst, "[ID] = " & [Text101] & "'"
    OUT_TIME = TIME()
    Me.Form.Requery
    
    Text101.Value = ""
    
    Text101.SetFocus
    
    End If
    End Sub
    Sorry, I can't get the expected result according to your 2nd post, can you help me check it?

    "Text101" is the textbox where the Barcode Scanner input the student no. while "Student" is the MASTER TABLE, which contains a field "IN_LESSON" which is a True/False DataType indicating whether the student is present....

    Thanks!
    Last edited by uut650; 05-21-08 at 10:23.

  10. #10
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    O.K here is your code but to mention in this way you don't keep the incom/outgoing record of students, you should have a table for dates linked to student table on ID with one to many relationship so you can keep the records of students for incom/outgoing.
    Code:
    Private Sub Text101_AfterUpdate()
    On Error GoTo Err_Handler
    
    If IsNull(DLookup("[IN_LESSON]", "Student", "[ID] =" & Me!Text101)) Then 'Check if the student is new or not?
        DoCmd.GoToRecord , , acNewRec 'If student is new then open a new record
        Me.ID = Text101 'put the bar code number in student ID
        Me!In.Value = Time 'its the first time the new commer is entering so we assume In time to be entered
        Me.IN_LESSON = True 'it show the student is present
        Text101.Value = "" 'refresh the barcode text box (not necesary)
        Text101.SetFocus
    Else
        DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Me!Text101, 0)) ' if the student ID is available then go to that record
        If Me.IN_LESSON Then 'to see if student is coming in or going out?
            Me!Out.Value = Time 'when IN_LESSON is true means student is leaving so put time in OUT
            Me.IN_LESSON = False 'make IN_LESSON false
            Text101.Value = ""
            Text101.SetFocus
        Else
            Me!In = Time 'IN_LESSON is false so the student is coming in
            Me!Out = "" 'OLD Out data to be removed
            Me.IN_LESSON = True
            Text101.Value = ""
            Text101.SetFocus
        End If
    End If
    
    sub_exit:
        Exit Sub
       
    Err_Handler:
      MsgBox "An error has occurred in this application. " _
    & "Please contact your technical support person and " _
    & "tell them this information:" _
    & vbCrLf & vbCrLf & "Error Number " & Err.Number & ", " _
    & Err.Description, _
    Buttons:=vbCritical
        Resume sub_exit:
    End Sub
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

  11. #11
    Join Date
    May 2008
    Posts
    4
    Really Thanks but the following error appeared:

    Error Number 3020, Update or CancelUpdate without AddNew or Edit

    Sorry to bother you again

  12. #12
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    Can you tell the error is belong to which line exactly? I need it to guess what is the problem on your app cuz I checked and raise no error on mine
    <<Never Walk on the Traveled Path, Because it only Leads you to where the Others have been.>>
    Graham Bell

Posting Permissions

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