From: yanto on
Hi,
I create an application to access finger print attendance device using
their SDK, the source code:

Dim vMachineNumber
Dim bConnected As Boolean
Dim CZKEM1 As Object


Private Sub cmdConnect_Click()
Dim ver As String
Dim dwEnrollNumber As String
Dim dwVerifyMode As Long
Dim dwInOutMode As Long
Dim timeStr As String
Dim i As Long
Dim dwMachineNum, dwEMachineNum, dwYear, dwMonth, dwDay, dwHour,
dwMinute, dwSecond, dwWorkcode, dwReserved As Long
Dim fso, txtfile
Dim LogStr As String

If bConnected Then
CZKEM1.Disconnect
cmdConnect.Caption = "Connect"
bConnected = False
lblInfo.Caption = ""
Else
'Make a connection
If CZKEM1.Connect_Net("192.168.1.125", 4370) Then
If CZKEM1.GetFirmwareVersion(vMachineNumber, ver) Then
lblInfo.Caption = "Version=""" & ver & """"
If CZKEM1.GetDeviceIP(vMachineNumber, ver) Then
lblInfo.Caption = lblInfo.Caption & ", IP=" & ver
End If
cmdConnect.Caption = "Disconnect"
bConnected = True
End If
Else
Beep
lblInfo.Caption = "Connect fail."
End If



If CZKEM1.ReadGeneralLogData(1) Then
Set dbs = CurrentDb()

While CZKEM1.SSR_GetGeneralLogData(1, dwEnrollNumber,
dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute,
dwSecond, dwWorkcode)
DoEvents
i = i + 1


'Write to database
strSQL = "INSERT INTO tblAttendants (EmployeeID, AttDate,
AttTime, Status) VALUES ('" & _
CStr(dwEnrollNumber) & "',#" & _
CDate(CStr(dwMonth) + "/" + CStr(dwDay) + "/" + CStr
(dwYear)) & "#,#" & _
CStr(dwHour) + ":" + CStr(dwMinute) + ":" + CStr
(dwSecond) & "#,'" & _
IIf(dwInOutMode = 0, "IN", "Out") & "');"
'MsgBox strSQL
dbs.Execute strSQL, dbFailOnError
Wend
dbs.Close
Set dbs = Nothing
End If
MsgBox "Proses ambil data selesai!"
frmSubAttendant.Requery
End If
End Sub

Private Sub Form_Load()
Dim s As String

bConnected = False

Set CZKEM1 = New CZKEM
'Set CZKEM1 = CreateObject("CZKEM")
CZKEM1.BASE64 = 0
vMachineNumber = 1
CZKEM1.GetSDKVersion s

End Sub


Private Sub Form_Unload(Cancel As Integer)
CZKEM1.Disconnect
Set CZKEM1 = Nothing
End Sub

this works good, untill I quit the application and I got an error: "Ms
Access has generated error and will be closed by window. You will need
to restart the program. An error log is being created"
and suddently quit from application.
The question are:
1. Do I miss something in my code?
2. Where is the error log created?
TIA
Yanto
From: Stefan Hoffmann on
hi Yanto,

yanto wrote:
> Dim vMachineNumber
You should always declare it explicitly using As Variant.

> Dim dwMachineNum, dwEMachineNum, dwYear, dwMonth, dwDay, dwHour,
> dwMinute, dwSecond, dwWorkcode, dwReserved As Long
Only dwReserved is of the data type Long. The others are Variant. In
opposite to VB, you don't have this kind of short declaration in VBA.

> Dim fso, txtfile
Same here.

> this works good, untill I quit the application and I got an error: "Ms
> Access has generated error and will be closed by window. You will need
> to restart the program. An error log is being created"
> and suddently quit from application.
> The question are:
> 1. Do I miss something in my code?
Imho not.

Make a simple test application, no tables, one form only:

Private WithEvents CZKEM1 As CZKEM
Private bConnected As Boolean

Private Sub Form_Load()

bConnected = False

Set CZKEM1 = New CZKEM

If CZKEM1.Connect_Net("192.168.1.125", 4370) Then
bConnected = True
Else
Beep
End If

End Sub

Private Sub Form_Close()

If bConnected Then
CZKEM1.Disconnect
End If
Set CZKEM1 = Nothing

End Sub


mfG
--> stefan <--
From: Dorian on
Is CZKEM1 always instantiated before your reference in UNLOAD procedure?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"yanto" wrote:

> Hi,
> I create an application to access finger print attendance device using
> their SDK, the source code:
>
> Dim vMachineNumber
> Dim bConnected As Boolean
> Dim CZKEM1 As Object
>
>
> Private Sub cmdConnect_Click()
> Dim ver As String
> Dim dwEnrollNumber As String
> Dim dwVerifyMode As Long
> Dim dwInOutMode As Long
> Dim timeStr As String
> Dim i As Long
> Dim dwMachineNum, dwEMachineNum, dwYear, dwMonth, dwDay, dwHour,
> dwMinute, dwSecond, dwWorkcode, dwReserved As Long
> Dim fso, txtfile
> Dim LogStr As String
>
> If bConnected Then
> CZKEM1.Disconnect
> cmdConnect.Caption = "Connect"
> bConnected = False
> lblInfo.Caption = ""
> Else
> 'Make a connection
> If CZKEM1.Connect_Net("192.168.1.125", 4370) Then
> If CZKEM1.GetFirmwareVersion(vMachineNumber, ver) Then
> lblInfo.Caption = "Version=""" & ver & """"
> If CZKEM1.GetDeviceIP(vMachineNumber, ver) Then
> lblInfo.Caption = lblInfo.Caption & ", IP=" & ver
> End If
> cmdConnect.Caption = "Disconnect"
> bConnected = True
> End If
> Else
> Beep
> lblInfo.Caption = "Connect fail."
> End If
>
>
>
> If CZKEM1.ReadGeneralLogData(1) Then
> Set dbs = CurrentDb()
>
> While CZKEM1.SSR_GetGeneralLogData(1, dwEnrollNumber,
> dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute,
> dwSecond, dwWorkcode)
> DoEvents
> i = i + 1
>
>
> 'Write to database
> strSQL = "INSERT INTO tblAttendants (EmployeeID, AttDate,
> AttTime, Status) VALUES ('" & _
> CStr(dwEnrollNumber) & "',#" & _
> CDate(CStr(dwMonth) + "/" + CStr(dwDay) + "/" + CStr
> (dwYear)) & "#,#" & _
> CStr(dwHour) + ":" + CStr(dwMinute) + ":" + CStr
> (dwSecond) & "#,'" & _
> IIf(dwInOutMode = 0, "IN", "Out") & "');"
> 'MsgBox strSQL
> dbs.Execute strSQL, dbFailOnError
> Wend
> dbs.Close
> Set dbs = Nothing
> End If
> MsgBox "Proses ambil data selesai!"
> frmSubAttendant.Requery
> End If
> End Sub
>
> Private Sub Form_Load()
> Dim s As String
>
> bConnected = False
>
> Set CZKEM1 = New CZKEM
> 'Set CZKEM1 = CreateObject("CZKEM")
> CZKEM1.BASE64 = 0
> vMachineNumber = 1
> CZKEM1.GetSDKVersion s
>
> End Sub
>
>
> Private Sub Form_Unload(Cancel As Integer)
> CZKEM1.Disconnect
> Set CZKEM1 = Nothing
> End Sub
>
> this works good, untill I quit the application and I got an error: "Ms
> Access has generated error and will be closed by window. You will need
> to restart the program. An error log is being created"
> and suddently quit from application.
> The question are:
> 1. Do I miss something in my code?
> 2. Where is the error log created?
> TIA
> Yanto
> .
>
From: yanto on
Thanks for response and correction, Stefan and Dorian,
According to Dorian question, my answer is yes, does anything wrong
with this? CMIIW
From: AccessVandal via AccessMonster.com on
Did you correct the code as suggested by Stefan?

With this
"Dim dwMachineNum, dwEMachineNum, dwYear, dwMonth, dwDay, dwHour,
dwMinute, dwSecond, dwWorkcode, dwReserved As Long"

So far I have never to even get it to work at all.

It's better to include the "Option Explicit" to check for any undeclared
objects in your code just in case there may be typos as well.

When you close the form, did it cause an error or just exiting Access?

yanto wrote:
>Thanks for response and correction, Stefan and Dorian,
>According to Dorian question, my answer is yes, does anything wrong
>with this? CMIIW

--
Please Rate the posting if helps you.

Message posted via http://www.accessmonster.com