inga
March 7th, 2005, 10:40 PM
Please HELP!
I am trying to check records in DB for a specific value. On record 2 or 3 (it varies) I get an overflow error. There are no numeric variables used in the application at all. The following is the code in question:
Private Sub BtnAddUp_Click()
On Error GoTo Err_BtnAddUp_Click
If IsNull(CustNameFirst) And IsNull(CustNameLast) Then
CustNameFirst.SetFocus
err.Description = "Customer must have First or Last Name"
GoTo Err_BtnAddUp_Click
End If
If IsNull(CustPhoneHome) And IsNull(CustPhoneWork) _
And IsNull(CustPhoneCell) Then
CustPhoneHome.SetFocus
err.Description = "Customer must have At Least One Phone Number"
GoTo Err_BtnAddUp_Click
End If
Dim errPhone As Boolean
If IsNull(CustPhoneHome) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneHome)
If errPhone = True Then
CustPhoneHome.SetFocus
err.Description = "Phone Number " & CustPhoneHome & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
If IsNull(CustPhoneWork) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneWork)
If errPhone = True Then
CustPhoneWork.SetFocus
err.Description = "Phone Number " & CustPhoneWork & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
If IsNull(CustPhoneCell) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneCell)
If errPhone = True Then
CustPhoneCell.SetFocus
err.Description = "Phone Number " & CustPhoneCell & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
DoCmd.GoToRecord , , acNewRec
Exit_BtnAddUp_Click:
Exit Sub
Err_BtnAddUp_Click:
MsgBox err.Description
End Sub
Function CheckPhone(stPhone As String) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("DBUpLog")
Dim nxt As Boolean
nxt = True
With rst
Do While nxt
If rst.EOF Then
CheckPhone = False
nxt = False
Else
' I get an overflow on the following line
If stPhone = rst!CustPhoneHome Or rst!CustPhoneWork Or rst!CustPhoneCell Then
CheckPhone = True
nxt = False
Else
.MoveNext
End If
End If
Loop
End With
rst.Close
End Function
DBUpLog Table is defined as follows:
Field Name Data Type Format Input Mask Indexed Required
EntryDate Date/Time Short Date Yes(dups ok) Yes
CustNameFirst Text (20) Yes(dups ok) No
CustNameLast Text (20) Yes(dups ok) No
CustPhoneHome Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
CustPhoneWork Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
CustPhoneCell Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
AgentName Text (10) Yes(dups ok) Yes
UserName Text (10) Yes(dups ok) Yes
I am trying to check records in DB for a specific value. On record 2 or 3 (it varies) I get an overflow error. There are no numeric variables used in the application at all. The following is the code in question:
Private Sub BtnAddUp_Click()
On Error GoTo Err_BtnAddUp_Click
If IsNull(CustNameFirst) And IsNull(CustNameLast) Then
CustNameFirst.SetFocus
err.Description = "Customer must have First or Last Name"
GoTo Err_BtnAddUp_Click
End If
If IsNull(CustPhoneHome) And IsNull(CustPhoneWork) _
And IsNull(CustPhoneCell) Then
CustPhoneHome.SetFocus
err.Description = "Customer must have At Least One Phone Number"
GoTo Err_BtnAddUp_Click
End If
Dim errPhone As Boolean
If IsNull(CustPhoneHome) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneHome)
If errPhone = True Then
CustPhoneHome.SetFocus
err.Description = "Phone Number " & CustPhoneHome & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
If IsNull(CustPhoneWork) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneWork)
If errPhone = True Then
CustPhoneWork.SetFocus
err.Description = "Phone Number " & CustPhoneWork & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
If IsNull(CustPhoneCell) Then
errPhone = False
Else
errPhone = CheckPhone(CustPhoneCell)
If errPhone = True Then
CustPhoneCell.SetFocus
err.Description = "Phone Number " & CustPhoneCell & " already recorded"
GoTo Err_BtnAddUp_Click
End If
End If
DoCmd.GoToRecord , , acNewRec
Exit_BtnAddUp_Click:
Exit Sub
Err_BtnAddUp_Click:
MsgBox err.Description
End Sub
Function CheckPhone(stPhone As String) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("DBUpLog")
Dim nxt As Boolean
nxt = True
With rst
Do While nxt
If rst.EOF Then
CheckPhone = False
nxt = False
Else
' I get an overflow on the following line
If stPhone = rst!CustPhoneHome Or rst!CustPhoneWork Or rst!CustPhoneCell Then
CheckPhone = True
nxt = False
Else
.MoveNext
End If
End If
Loop
End With
rst.Close
End Function
DBUpLog Table is defined as follows:
Field Name Data Type Format Input Mask Indexed Required
EntryDate Date/Time Short Date Yes(dups ok) Yes
CustNameFirst Text (20) Yes(dups ok) No
CustNameLast Text (20) Yes(dups ok) No
CustPhoneHome Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
CustPhoneWork Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
CustPhoneCell Text (10) !\(999")"000\-0000;;_ Yes(no dups) No
AgentName Text (10) Yes(dups ok) Yes
UserName Text (10) Yes(dups ok) Yes