I have 2 buttons and 4 textboxes in the form.
Textboxes: tbxFromDate, tbxToDate, tbxFrmNo, tbxToNo
Buttons: btnCheckDate, btnCheckNo
Date format to be entered into tbxFrmDate & tbxToDate is "YYYYMMDD".
Codes for bthCheckNo onClick...
Code:
Private Sub btnCheckNo_Click()
Dim strSQL, query, stDocName, insertSQL, errMsg As String
Dim dbTemp As DAO.Database
Dim rstTemp As DAO.Recordset, rst As DAO.Recordset
Dim qdef As QueryDef
Dim processed As Integer
Const cstrNewTableName As String = "T_RESULT"
Set dbTemp = CurrentDb
DoCmd.SetWarnings False
DoCmd.Echo False
If (IsNull(Me.tbxFrmNo)) Or (IsNull(Me.tbxToNo)) Then
errMsg = "From No & To No must not be blank!!"
GoTo err_handler
ElseIf (IsNumeric(Me.tbxFrmNo) = False) Or (IsNumeric(Me.tbxToNo) = False) Then
errMsg = "Please enter numbers only!!"
GoTo err_handler
ElseIf (Me.tbxFrmNo <= 0) Then
errMsg = "From No must be more than 0!!"
GoTo err_handler
ElseIf (Me.tbxToNo <= 0) Then
errMsg = "To No must not be more than 0!!"
GoTo err_handler
ElseIf (Me.tbxFrmNo > Me.tbxToNo) Then
errMsg = "From No must be smaller than To No!!"
GoTo err_handler
End If
'To do stuff with database later on
Exit_btnCheckNo_Click:
Exit Sub
err_handler:
DoCmd.SetWarnings True
MsgBox errMsg
GoTo Exit_btnCheckNo_Click
Err_btnCheckNo_Click:
MsgBox Err.Description
Resume Exit_btnCheckNo_Click
End Sub
Code for btnCheckDate onclick is...
Code:
Private Sub btnCheckDate_Click()
Dim strSQL, query, stDocName, insertSQL, errMsg As String
Dim dbTemp As DAO.Database
Dim rstTemp As DAO.Recordset, rst As DAO.Recordset
Dim qdef As QueryDef
Const cstrNewTableName As String = "T_RESULT"
Set dbTemp = CurrentDb
If (IsNull(Me.tbxFromDate)) Or (IsNull(Me.tbxToDate)) Then
errMsg = "From Date & To Date must not be blank!!"
GoTo err_handler
ElseIf (IsNumeric(Me.tbxFromDate) = False) Or (IsNumeric(Me.tbxToDate) = False) Then
errMsg = "Please enter numbers only!!"
GoTo err_handler
End If
If (DateValue(Right(Me.[tbxFromDate], 2) & "-" & MonthName(Mid(Me.[tbxFromDate], 5, 2), True) & "-" & Left(Me.[tbxFromDate], 4)) > DateValue(Right(Me.[tbxToDate], 2) & "-" & MonthName(Mid(Me.[tbxToDate], 5, 2), True) & "-" & Left(Me.[tbxToDate], 4))) Then
errMsg = "From date have to be earlier than to date!!"
GoTo err_handler
End If
'To do stuff with database later
Exit_btnCheckDate_Click:
Exit Sub
err_handler:
DoCmd.SetWarnings True
MsgBox errMsg
GoTo Exit_btnCheckDate_Click
Err_btnCheckDate_Click:
MsgBox Err.Description
Resume Exit_btnCheckDate_Click
End Sub
For now I only have checking for the textboxes. When I click on btnCheckDate when the textboxes are blank, it works fine.
Error message is shown in message box that pops up then I click ok, and the form still works.
However, when I click on btnCheckNo when the textboxes are blank, error message is shown in message box that pops up then I click ok, and access hangs.