•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 402,455 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,900 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 6309 | Replies: 15 | Solved
![]() |
•
•
Join Date: Sep 2006
Posts: 50
Reputation:
Rep Power: 3
Solved Threads: 1
sir yomet
hello sir i have some good news for you, i was able to set the TIMEOUT, but there is few error i want to fix..
SAMPLE OUTPUT mysql
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:22 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:48 | Access | 546 | 21:32:09 |
2002-05-02 | 21:30:55 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:19 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:06 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:08 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:09 | Access | 234 | 21:32:09 |
---------------------------------------------------------------------------------
i just revise some of your sample code sir... as you see in the output i
the code read only the last TimeIn... the right output shoul be like this
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:22 |
2002-05-02 | 21:30:48 | Access | 546 | 21:31:19 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
--------------------------------------------------------------------------------
read only the first TimeIn and the LAST record and put this as TimeOut Base on their CARDNUMBER and the DATE...i need your suggestions sir...thanks..and if you can provide me a bit of code...thanks
THE CODE I USE SIR
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=localhost;" & " DATABASE=time_and_attendance;" & "UID=root;PWD=admin; OPTION=3"
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
Call ExecuteCommand
If rs.EOF Then ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'"
End If
rs.Close
Set rs = Nothing
End If
hello sir i have some good news for you, i was able to set the TIMEOUT, but there is few error i want to fix..
SAMPLE OUTPUT mysql
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:22 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:48 | Access | 546 | 21:32:09 |
2002-05-02 | 21:30:55 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:19 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:06 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:08 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:09 | Access | 234 | 21:32:09 |
---------------------------------------------------------------------------------
i just revise some of your sample code sir... as you see in the output i
the code read only the last TimeIn... the right output shoul be like this
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:22 |
2002-05-02 | 21:30:48 | Access | 546 | 21:31:19 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
--------------------------------------------------------------------------------
read only the first TimeIn and the LAST record and put this as TimeOut Base on their CARDNUMBER and the DATE...i need your suggestions sir...thanks..and if you can provide me a bit of code...thanks
THE CODE I USE SIR
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=localhost;" & " DATABASE=time_and_attendance;" & "UID=root;PWD=admin; OPTION=3"
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
Call ExecuteCommand
If rs.EOF Then ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'"
End If
rs.Close
Set rs = Nothing
End If
•
•
Join Date: Nov 2005
Location: Montreal, QC (Almost)
Posts: 130
Reputation:
Rep Power: 3
Solved Threads: 9
royaloba,
I can see where you code is going wrong and there are two quite simple errors.
1) What you do is adding a record every time you read a line wihtout first verifying if that card has already been used today.
2) The UPDATE statement later on will update all the records - not only the ones for that specific card and day. This error comes from my own code so I take full responsibility for it, I forgot to add the WHERE clause in the code I gave you.
Using your own code I will show you what I am talking about and how to correct it.
BTW, please use the code tags like this
[ code ]
Here goes all your code.
Please remove the spaces between the square brackets "[" and "]" and the "code" and "/code" parts
[ /code ]
OK, here goes
Seeing my last answer I would like to say sorry for misleading you, I was tired and didn't read the code correctly, there was no syntax error, just my eyes seeing double... :o
As far as I can see this should do the trick. Try it out and tell me how it works.
Happy coding
Yomet
I can see where you code is going wrong and there are two quite simple errors.
1) What you do is adding a record every time you read a line wihtout first verifying if that card has already been used today.
2) The UPDATE statement later on will update all the records - not only the ones for that specific card and day. This error comes from my own code so I take full responsibility for it, I forgot to add the WHERE clause in the code I gave you.
Using your own code I will show you what I am talking about and how to correct it.
BTW, please use the code tags like this
[ code ]
Here goes all your code.
Please remove the spaces between the square brackets "[" and "]" and the "code" and "/code" parts
[ /code ]
OK, here goes
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=localhost;" & " DATABASE=time_and_attendance;" & "UID=root;PWD=admin; OPTION=3"
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
'**********************
'At this point you have fresh data in your array and what you
'WANT to do is verify if the current card, in Card(data(5)), has
'already been used today.
'What you need here is a condition to see if the card has already
'been used. Actually the IF statement you use later is almost there, i.e.
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
Call ExecuteCommand
'If rs.EOF Then ' DATA HAS BEEN USED
If NOT rs.EOF Then 'Data has NOT been used so insert it.
'**********************
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
'**********************
'Now you have inserted the data into your database since it was
'not there to begin with.
'However, if the data was already in the table you need to update
'the TimeOut with the current time. So we scrap the If statement
'(since we used it above) and use the else clause.
Else
'**********************
'Set rs = New ADODB.Recordset
'squery = "": squery = "Select * from tblattendance where Date='" & 'data(0) & "' and CardNumber='" & data(5) & "'"
'Call ExecuteCommand
'If rs.EOF Then ' DATA HAS BEEN USED
'conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'"
'**********************
'The new UPDATE statement
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'" & _
WHERE Date='" & 'data(0) & "' and CardNumber='" & data(5) & "'"
'**********************
End If
rs.Close
Set rs = Nothing
End IfSeeing my last answer I would like to say sorry for misleading you, I was tired and didn't read the code correctly, there was no syntax error, just my eyes seeing double... :o
As far as I can see this should do the trick. Try it out and tell me how it works.
Happy coding
Yomet
•
•
Join Date: Sep 2006
Posts: 50
Reputation:
Rep Power: 3
Solved Threads: 1
hello sir Yomet
first thanks for helping me with this project
the problem is when i put the "if not rs.eof then" the return record in the data base in empty... and when i replace it with "if rs.eof" the ouput for all the timeout is the same..sir i attach a sample program, i convert it to access so you could determine where is the problem occurs..thanks sir..
first thanks for helping me with this project
the problem is when i put the "if not rs.eof then" the return record in the data base in empty... and when i replace it with "if rs.eof" the ouput for all the timeout is the same..sir i attach a sample program, i convert it to access so you could determine where is the problem occurs..thanks sir..
•
•
Join Date: Nov 2005
Location: Montreal, QC (Almost)
Posts: 130
Reputation:
Rep Power: 3
Solved Threads: 9
royaloba,
Thanks for taking the time to convert your database into Access, it helped.
Now for what I found:
1) There seems to be some problem with the "ExecuteCommand" sub since it never gives back a recordset with records in it. However when I replaced that line with
2) I had to revert to your original code for inserting and updating records by using
You were correct in using
Hope this code works and keep up the good work.
Yomet
Thanks for taking the time to convert your database into Access, it helped.
Now for what I found:
1) There seems to be some problem with the "ExecuteCommand" sub since it never gives back a recordset with records in it. However when I replaced that line with
rs.Open squery, conn it gave the expected results.2) I had to revert to your original code for inserting and updating records by using
conn.Execute instead of db.Execute because when using the mix between DAO and ADODB the record was not saved by DAO before the ADODB went to find it. Weird I know but by using the following code everything went well. Open sFile For Input As #inFile
' Set db = DBEngine.OpenDatabase(App.Path & "\db1.mdb")
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date=#" & data(0) & "# AND CardNumber='" & Card(data(5)) & "'"
' Call ExecuteCommand
rs.Open squery, conn
If rs.EOF Then
conn.Execute "INSERT INTO tblattendance ([Date], [TimeIn], CardNumber) " & _
"VALUES (#" & data(0) & "#, " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Card(data(5)) & "')"
'Set rs = New ADODB.Recordset
'squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
'Call ExecuteCommand
'If rs.EOF Then ' DATA HAS BEEN USED
Else
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "' where Date=#" & data(0) & "# AND CardNumber='" & Card(data(5)) & "'"
End If
rs.Close
Set rs = Nothing
End If
Wend
MsgBox "Record successfully saved ", vbInformation + vbOKOnly, "Record Saved"
Unload Me
Me.Show
Close #inFile
Exit SubYou were correct in using
If rs.EOF instead of If Not rs.EOF, typical brain-fart on my behalf.Hope this code works and keep up the good work.
Yomet
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Microsoft OLEDB Chart Control Version 6 question
- Next Thread: Sorting has me out of sorts.


Linear Mode