MarkWaddington
Programmer
Hi, something has gone wrong with my main form in my database. When I open the form I get a blank error message, if I try to catch the error number, it tells me the error number is "0".
I can't see anything wrong with my code, the only way i can stop the message box from appearing is by taking out all my error handling code - but I don't really want to do that.
Has anybody got any clues as to what I can do to determine the source of the error?
Here's the code that is attached to my form's "on load" event handler - strangely enough even if I remove all this I still get the error, but this is the only code that runs when I open the form so go figure!
Any help greatly appreciated.
Private Sub Form_Load()
On Error GoTo ErrorHandler
If ((RegNo) > 0) Then
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("LockedRecords", dbOpenDynaset)
If (rs.RecordCount) = 0 Then
With rs
.AddNew
.Fields("StaffName"
= CurrentUser()
.Fields("LockedRecord"
= RegNo
.Update
End With
Else
With rs
.MoveFirst
Do While Not .EOF
If .Fields("LockedRecord"
= (RegNo) Then
MsgBox "This record has been locked by user " + .Fields("StaffName"
+ ". This is most probably because they are viewing the record right now. Please try again later, or inform the member of staff in question that you wish to view this record."
DoCmd.Close
Exit Sub
End If
.MoveNext
Loop
End With
With rs
.AddNew
.Fields("StaffName"
= CurrentUser()
.Fields("LockedRecord"
= RegNo
.Update
End With
Set rs = Nothing
Set db = Nothing
End If
End If
If (Forms!Client!Gender = "Female"
Then
Forms!Client.Section(0).BackColor = 14135039
End If
If (Forms!Client!Gender = "Male"
Then
Forms!Client.Section(0).BackColor = "16562343"
End If
If (Forms!Client!Gender = "Not Known"
Then
Forms!Client.Section(0).BackColor = 10079487
End If
With CodeContextObject
If (.Disability = 0) Then
Forms!Client!DisabilityDetails.Visible = False
End If
If (.Disability = -1) Then
Forms!Client!DisabilityDetails.Visible = True
End If
End With
ErrorHandler:
MsgBox Err.Description
If (Err.Number = 2427) Then
MsgBox "You are a read only user, if you feel you should have higher access privileges, please contact the IT Administrator", vbInformation
End If
End Sub
I can't see anything wrong with my code, the only way i can stop the message box from appearing is by taking out all my error handling code - but I don't really want to do that.
Has anybody got any clues as to what I can do to determine the source of the error?
Here's the code that is attached to my form's "on load" event handler - strangely enough even if I remove all this I still get the error, but this is the only code that runs when I open the form so go figure!
Any help greatly appreciated.
Private Sub Form_Load()
On Error GoTo ErrorHandler
If ((RegNo) > 0) Then
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("LockedRecords", dbOpenDynaset)
If (rs.RecordCount) = 0 Then
With rs
.AddNew
.Fields("StaffName"
.Fields("LockedRecord"
.Update
End With
Else
With rs
.MoveFirst
Do While Not .EOF
If .Fields("LockedRecord"
MsgBox "This record has been locked by user " + .Fields("StaffName"
DoCmd.Close
Exit Sub
End If
.MoveNext
Loop
End With
With rs
.AddNew
.Fields("StaffName"
.Fields("LockedRecord"
.Update
End With
Set rs = Nothing
Set db = Nothing
End If
End If
If (Forms!Client!Gender = "Female"
Forms!Client.Section(0).BackColor = 14135039
End If
If (Forms!Client!Gender = "Male"
Forms!Client.Section(0).BackColor = "16562343"
End If
If (Forms!Client!Gender = "Not Known"
Forms!Client.Section(0).BackColor = 10079487
End If
With CodeContextObject
If (.Disability = 0) Then
Forms!Client!DisabilityDetails.Visible = False
End If
If (.Disability = -1) Then
Forms!Client!DisabilityDetails.Visible = True
End If
End With
ErrorHandler:
MsgBox Err.Description
If (Err.Number = 2427) Then
MsgBox "You are a read only user, if you feel you should have higher access privileges, please contact the IT Administrator", vbInformation
End If
End Sub