Ms Access got an error and quit

Y

yanto

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
 
S

Stefan Hoffmann

hi Yanto,
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 <--
 
D

Dorian

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".
 
Y

yanto

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

AccessVandal via AccessMonster.com

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?
 
J

John W. Vinson

Did you correct the code as suggested by Stefan?

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

Do note that this dimensions dwReserved as a Long - but dims all of the other
variables as Variants, the default.

You must use

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

to specify each of the variables as Long.
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.

Absolutely and always.
 
Y

yanto

Do note that this dimensions dwReserved as a Long - but dims all of the other
variables as Variants, the default.

You must use
Thanks for all response, I will try soon.
 
Y

yanto

I forget something, the error come out when I close the form and also
quit access, because I only have one form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top