Solved VBA To Add Record

mtagliaferri

Registered User.
Local time
Today, 22:09
Joined
Jul 16, 2006
Messages
524
I am working with a frmPSA that contains a sfrmPSATimeline, both are locked for edits and additions.

Within the frmPSA I have a cmdEdit button with the below code to unlock both forms for editing, and this works fine.

Code:
Private Sub CmdEdit_Click()
    Me.Form.AllowEdits = True
    Me.FirstName.SetFocus
    Me.CmdEdit.Visible = False
    Me.sfrmPSATimeline.Form.AllowEdits = True
    Me.sfrmPSATimeline.Form.AllowAdditions = True
End Sub

I have a frmPSAList with a cmdAdd button to add a new record, so I am looking at unlocking the frmPSA and the sfrmPSATimeline similarly to the edit function with the below code.

Code:
Private Sub CmdAdd_Click()
    DoCmd.OpenForm "frmPSA", acNormal, "", "", acAdd
    Forms!frmPSA!CmdEdit.Visible = False
    Forms!frmPSA!FirstName.SetFocus
    Me.sfrmPSATimeline.Form.AllowEdits = True
    Me.sfrmPSATimeline.Form.AllowAdditions = True
End Sub

However I get a Compile error ‘Method or data member not found’
Screenshot 2024-09-17 134003.png


Thanks
 
By default access names the subform control the same name as the subform inside of it. However, sometimes it does not depending on how you added it. Recheck the name of the subform control that holds the subform.
 
Check the name of your subfomcontrol.
It should really come up with intellisense as you type it. If it does not, then that is the reason.

I found a problem with another member on their DB using intellisense.
 
You just start typing in what you have and it will present the properties and methods for you to use.
Where is that second block of code located?
You say you want to unlock a second form?, so you should be using the same syntax as you do for AllowEdits?

Me refers to the form the code is running in, and that does not appear to have that subform in it. :(

Try
Code:
Forms!frmPSA!sfrmPSATimeline.Form.AllowEdits = True
 
You just start typing in what you have and it will present the properties and methods for you to use.
Where is that second block of code located?
You say you want to unlock a second form?, so you should be using the same syntax as you do for AllowEdits?

Me refers to the form the code is running in, and that does not appear to have that subform in it. :(

Try
Code:
Forms!frmPSA!sfrmPSATimeline.Form.AllowEdits = True
Thanks that has worked by changing AllowEdits to AllowAdditions.

Thanks for the help!
 

Users who are viewing this thread

Back
Top Bottom