Buttons

mis

Registered User.
Local time
Today, 15:02
Joined
Dec 15, 2003
Messages
55
Forum,

I have got a Delete button, as well as an edit button on a form so that the user can delete and/or edit information. I have desided to lock all the txtboxes so the user can't change information with out clicking on the edit button first.

I need the edit button to unlock all the locked txtboxs on the form have tried to do this with the expression builder but with no luck, any ideas this is what i had (=[ContactNo].locked=no).

The delete button included brings up a message box saying (You are about to delete 1 record(s)...... is there a way to change this to "Are you sure you want to delete this record!". Also if you click cancel another message box comes up with (The DoMenuItem action was canceled) away way of getting rid of this as it will confuse people.

Cheers
 
Code:
Dim ctl As Control
For Each ctl In Me
    If ctl.ControlType = acTextBox Then
        ctl.Locked = False
        ctl.Enabled = True
    End If
Next
Set ctl = Nothing
 
mis said:
Forum,

The delete button included brings up a message box saying (You are about to delete 1 record(s)...... is there a way to change this to "Are you sure you want to delete this record!". Also if you click cancel another message box comes up with (The DoMenuItem action was canceled) away way of getting rid of this as it will confuse people.

Cheers
You have to turn the warnings off. Also, you have to trap for those type of errors. Here is a delete routine that I use [I addded the code to turn the warnings off for you but I do not use it]...
Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
    End If
    
Exit_bDelete_Click:
    Exit Sub
    
Err_bDelete_Click:
    If Err = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
HTH
 
Thanks

Thanks for that
 
You have to turn the warnings off. Also, you have to trap for those type of errors. Here is a delete routine that I use [I addded the code to turn the warnings off for you but I do not use it]...
Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
    End If
    
Exit_bDelete_Click:
    Exit Sub
    
Err_bDelete_Click:
    If Err = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
HTH

any idea of why I get "TheRunCommand action was canceled" error message when deleting a record ?
 

Users who are viewing this thread

Back
Top Bottom