** form properties **

MS_Access_Amature

Registered User.
Local time
Today, 15:58
Joined
Nov 10, 2010
Messages
56
I want to change FORM2 properties from when you click a button in FORM1 so you can't edit, delete, or change anything until you click the Edit button. What am I doing wrong?

Code:
Private Sub ButtonCompany_Click()
On Error GoTo MyErrorControl

    DoCmd.OpenForm "MyCompanyInfo"
    
    Forms!MyCompanyInfo!Form.AllowEdits = False
    Forms!MyCompanyInfo!Form.AllowAdditions = False
    Forms!MyCompanyInfo!Form.AllowDeletions = False
    
    DoCmd.Close acForm, Me.Name, acSaveNo
    
    Exit Sub
MyErrorControl:
    Select Case Err.Number
    Case 0
        Resume Next
    Case Else
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "ButtonCompany_Click ERROR"
        Resume Next
    End Select
End Sub
 
In the form "MyCompanyInfo" use the On Current event to lock the form down.

Code:
    Me.AllowEdits = False
    Me.AllowAdditions = False
    Me.AllowDeletions = False

Your edit button can then set the properties to True.
 
Thanks.
It works, but does this effect other commands?
On my ButtonNew (button user clicks to add new record) I have

DoCmd.GoToRecord , , acNewRec

But when I run it, an error message pops up telling me I can't go to that record. Other words, I can't create new record. Is it because I disabled edit, delete, additions or what else could be the problem??
 
If you're doing what it is I think you are trying to do ie lock down form2 clicking a button on form1 then the Oncurrent event is not what you need as this will lock down the form as long as it has focus and also for every record that it is bound to.

From form1's button click event, instead try

Code:
Form_MyCompanyInfo.AllowEdits = False
Form_MyCompanyInfo.AllowAdditions = False
Form_MyCompanyInfo.AllowDeletions = False

When the form loads though you need to remember that these properties will not be called.
 
I did it on the Load Event on Form2

then when i click edit or new i disable them before i run the command.

Everything works now.

Thanks to all.
 
Thanks.
It works, but does this effect other commands?
On my ButtonNew (button user clicks to add new record) I have

DoCmd.GoToRecord , , acNewRec

But when I run it, an error message pops up telling me I can't go to that record. Other words, I can't create new record. Is it because I disabled edit, delete, additions or what else could be the problem??

That is correct. It is doing what you told it.

Since you have turned off with Me.AllowAdditions = False then you must enable it in your new buttom

Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
 
If you're doing what it is I think you are trying to do ie lock down form2 clicking a button on form1 then the Oncurrent event is not what you need as this will lock down the form as long as it has focus and also for every record that it is bound to.

It really has has nothing to do with Focus. That is incorrect.

If you are creating an edit button then you want to be sure each record is lock until the edit button is selected. The best event to insure this is the On Current event. It fires when you navigate to a new record (nothing to do with the form receiving or loosing or focus). This way you now that every record viewed is locked until the edit button is clicked.

If you are only viewing a single record and not allowing records to be added then the On Load event might work. As soon as you add the ability to view additional records or add record then the On Load event will only work for the very first record. You will have to figure all the other events that fire to allow you to lock record as the user navigate. If you don;t use the On Current event then you will have to put code in a lot of places to try to trap the navigation. OR just use the On Current Event. It works great for viewing a single record or multiple records.
 
I have a really quick question that has to to with the topic (form properties)...

How do I call an event from another event on the same form?

Private Sub UserPasswordConfirmation_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo MyErrorControl

If KeyCode = vbKeyReturn Then
'Call the OkButtonClick Event on this same form
End If

Exit Sub
MyErrorControl:
Select Case Err.Number
Case 0
Resume Next
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "UserPasswordConfirmation_KeyDown ERROR"
Resume Next
End Select
End Sub
 
To run the code in the OkButton button's On Click event use:

Code:
Call OkButton_Click()

Why all the code code below?

Code:
Private Sub UserPasswordConfirmation_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo MyErrorControl

If KeyCode = vbKeyReturn Then
     Call OkButton_Click()
End If

Exit Sub
MyErrorControl:
Select Case Err.Number
Case 0
Resume Next
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "UserPasswordConfirmation_KeyDown ERROR"
Resume Next
End Select
End Sub

This functionality is already built into Access. All you need to do is set the OkButton's property for Default to Yes. When the Enter key is press it will automatically click the command button. No VBA code required!

See attached Screenshot
 

Attachments

  • CommandButton_Default.png
    CommandButton_Default.png
    21.5 KB · Views: 103

Users who are viewing this thread

Back
Top Bottom