Form open acReadOnly; how can I add new records?

  • Thread starter Thread starter avandorpe
  • Start date Start date
A

avandorpe

Let me start with I have slim to no experience coding.

I am working in Access 2003, VBA.

I have a MsgBox that allows the user to indicate whether they want to
add a new record. The form (whether they intend to add or edit) opens
read only. I need to allow an add if that's what they choose while
still protecting the rest of the data once they are in. I've tried the
following code with no luck.

DoCmd.OpenForm "frmAccountEntry", acNormal, , , acReadOnly

Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec

I've tried adding a line of code before the Me.AllowAdditions line that
sets the focus to the form but that doesn't seem to work either. I know
what I am trying to do but not sure if it is even possible. Can anyone
give me some either help with my code or let me know if I am chasing
something that is illogical?

Thanks in advance for any assistance you can lend.

-Amy
 
ReadOnly is Read Only! You need to do a couple of things to accomplish your
goals.

Replace acReadOnly with acFormPropertySettings. This means that the form will
open according the properties you've set for the form in its Property Box.

Go into Design View for the form, then go into the Properties Box and set
these options:
Allow Edits No
Allow Additions No
Allow Deletions No

Now your form is essentially "read only" and the data "protected." It can't
be edited, deleted or new records added. Now, when you want to allow any of
these activities, simply insert the code Me.AllowAdditions = True, Me.
AllowEdits = True or Me.AllowDeletions = True in the appropriate place.

Remember after carrying out whichever activity to set the appropriate
property back to No to return your "read only" status!
 
First, thank you for your replies.

Before posting this I did try response #2 in this thread and it didn't
work.

Regarding reponse #3, I will give this a try another day because I'm
short on time and this will affect more situations in the app than I
have been allowed time to code for.

I did find a "work-around". If anyone is interested...I have an "add
new record" command button on my form that works even while the form is
readonly.

**Code behind button:

Private Sub AddNewRecord_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub

So what I did was made the Private Sub AddNewRecord_Click() - Public
Sub AddNewRecord_Click() and added that line to my code as such and it
works.

If MsgBox("Do you want to Add a new account?" & vbCrLf & "If you answer
No, Account Entry will open in Edit mode.", vbYesNo) = vbYes Then
DoCmd.OpenForm "frmAccountEntry", acNormal, , , acReadOnly
Forms!frmAccountEntry.AddNewRecord_Click
Exit Sub

Thank you to all that answered. I appreciate all the knowledge you are
willing to invest...

Best regards,
Amy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top