Results 1 to 3 of 3
  1. #1
    charis89 is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Aug 2015
    Posts
    8

    Access hangs after clicking ok for message box after clicking button on form

    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.

  2. #2
    charis89 is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Aug 2015
    Posts
    8
    I got it...
    The problem is "DoCmd.Echo False"
    I'm not sure why but once I take that out, access no longer hangs

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Echo turns screen updating off and on - false=off and true =on. google 'docmd.echo' to find out more

    if you are using it then you need to 'pair' these commands and ensure that the 'on' action cannot be bypassed as a result of the code flow or some event which causes an error

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2014, 03:29 PM
  2. Replies: 10
    Last Post: 07-17-2014, 09:39 PM
  3. Replies: 3
    Last Post: 10-30-2013, 05:59 AM
  4. Replies: 5
    Last Post: 08-02-2012, 02:05 PM
  5. Enable button in the master form when clicking in the detail
    By DistillingAccess in forum Programming
    Replies: 8
    Last Post: 08-03-2010, 10:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums