[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Where to place AllowEdits with Error message box in MS Access

I have a button on my form that switches it between allowing edits and not.  The default is that the form is read-only; clicking the buttom allows edits, then clicking a second time reverts to read only (see code below).

I have a function to validate data (courtesy of an expert here in my first question).  Code below.  

The problem is that if the validation function finds a problem, after a new valid entry is made, the form still allows edits.  Any suggestions on where to add an allowedits = false so that the original button works?  Thanks!
Private Sub cmdEdit_Click()
Dim cap As String
cap = Me.cmdEdit.Caption
 
Select Case cap
 
Case "Edit Record"
    With Me
        .AllowEdits = True
        .cmdEdit.Caption = "Save"
        .cmdEdit.ForeColor = 128
        .cmdEdit.FontBold = True
        
        'the following deactivates buttons not associated with editing a case
        .cmdAddRecord.Enabled = False
        .cmdDelRecord.Enabled = False
        .cmdGoCase.Enabled = False
        .cmdSearch.Enabled = False
        .cmdOpenFQForm.Enabled = False
        
        'the following activates buttons associated with editing a case
        .cmdSelf.Enabled = True
        .cmdScdryApp.Enabled = True
        .cmdAddRmk.Enabled = True
        .cmdBrowse.Enabled = True
        
        .Refresh
    End With
 
Case "Save"
    With Me
        .AllowEdits = False
        .cmdEdit.Caption = "Edit Record"
        .cmdEdit.ForeColor = 0
        .cmdEdit.FontBold = False
        
        'the following activates buttons not associated with editing a case
        .cmdAddRecord.Enabled = True
        .cmdDelRecord.Enabled = True
        .cmdGoCase.Enabled = True
        .cmdSearch.Enabled = True
        .cmdOpenFQForm.Enabled = True
        
        'the following deactivates buttons associated with editing a case
        .cmdSelf.Enabled = False
        .cmdScdryApp.Enabled = False
        .cmdAddRmk.Enabled = False
        .cmdBrowse.Enabled = False
        
        'Test for validity
        If Not ValidData() Then Exit Sub
        
        .AllowEdits = False
        
        .Refresh
    End With
 
End Select
 
End Sub
 
Private Function ValidData() As Boolean
ValidData = True
 
'this function tests if all data entered are logical.  right now, it just tests for dates
'copy the if statement to add other tests and message boxes
 
     'Check for values in date textboxes
     If IsNull(Me.Response_Date.Value) Then
         Call MsgBox("Please enter a value in the response date field.")
         Me.Response_Date.SetFocus
         ValidData = False
         Exit Function
     End If
     
     If IsNull(Me.Date_Received.Value) Then
         Call MsgBox("Please enter a value in the received date field.")
         Me.Date_Received.SetFocus
         ValidData = False
         Exit Function
     End If
 
     'Check for acceptable values
     If Me.Response_Date.Value < Me.Date_Received Then
         Call MsgBox("The Response Date entered is prior to the Date Received." & vbCrLf & "Please enter a valid Response Date.")
         ValidData = False
         Me.Response_Date.Value = Null
         Me.Response_Date.SetFocus
         Exit Function
     End If
 
End Function

Open in new window

0
ppontius
Asked:
ppontius
  • 2
1 Solution
 
milduraitCommented:
ppontius
Did you try like below?
Select Case cap
 
Case "Edit Record"
    With Me
        .AllowEdits = True
        .cmdEdit.Caption = "Save"
        .cmdEdit.ForeColor = 128
        .cmdEdit.FontBold = True
        
        'the following deactivates buttons not associated with editing a case
        .cmdAddRecord.Enabled = False
        .cmdDelRecord.Enabled = False
        .cmdGoCase.Enabled = False
        .cmdSearch.Enabled = False
        .cmdOpenFQForm.Enabled = False
        
        'the following activates buttons associated with editing a case
        .cmdSelf.Enabled = True
        .cmdScdryApp.Enabled = True
        .cmdAddRmk.Enabled = True
        .cmdBrowse.Enabled = True
        
        .Refresh
    End With
 
Case "Save"
    'Test for validity
    If Not ValidData() Then Exit Sub
        
    With Me
        .AllowEdits = False
        .cmdEdit.Caption = "Edit Record"
        .cmdEdit.ForeColor = 0
        .cmdEdit.FontBold = False
        
        'the following activates buttons not associated with editing a case
        .cmdAddRecord.Enabled = True
        .cmdDelRecord.Enabled = True
        .cmdGoCase.Enabled = True
        .cmdSearch.Enabled = True
        .cmdOpenFQForm.Enabled = True
        
        'the following deactivates buttons associated with editing a case
        .cmdSelf.Enabled = False
        .cmdScdryApp.Enabled = False
        .cmdAddRmk.Enabled = False
        .cmdBrowse.Enabled = False
        
            .AllowEdits = False
        
        .Refresh
    End With
 
End Select

Open in new window

0
 
ppontiusAuthor Commented:
That did work!  I thought I had tried it, but in the myriad of combinations, I guess I had missed it.  Thanks a bunch!
0
 
milduraitCommented:
no problem mate, good luck with your app.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now