Disabling New Records on Forms in VB

J

John Ortt

Hi Everyone,

I have designed a form which successfully supresses the ability to create
new records by setting the AllowAdditions property to "No".

The problem is that when I open the form using the code below the form once
again allows additions and I can't figure out how to prevent this.

I tagged the "Me.AllowAdditions = False" into the openargs section but to no
avail.

If anyone can spot the problem in my code I would be very grateful.

Thanks,

John

******* Start Code *******

Private Sub cmdView_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmForm"
stLinkCriteria = "[strIndex]=" & Me.ctlIndex.Value
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
Me.AllowAdditions = False

End Sub

******** End Code ********
 
S

SusanV

Hi John,

Put the Me.
AllowAdditions = False line in the On Open argument of the form, rather than
in the sub of the code calling the form.
 
A

Al Campagna

John,
If, in design mode, you set the AllowAdditions to NO, then there's no need to involve
AllowAdditions in the form opening code. The form will open with that property already
set, and will remain set until you change that property in the form code, or change the
design setting.
Also, the OpenArgs argument in the OpenForm method does not handle "code". It used to
pass a variable to the form.

And, it appears that the use of acFormEdit is overriding the form's AllowAdditions
setting.
Just try....
DoCmd.OpenForm stDocName,,, stLinkCriteria
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
J

John Ortt

Cheers Al,

You were right, simply removing the "acFormEdit" from the string is allowing
it to work as intended.

Thank you very much.

John


Al Campagna said:
John,
If, in design mode, you set the AllowAdditions to NO, then there's no
need to involve AllowAdditions in the form opening code. The form will
open with that property already set, and will remain set until you change
that property in the form code, or change the design setting.
Also, the OpenArgs argument in the OpenForm method does not handle
"code". It used to pass a variable to the form.

And, it appears that the use of acFormEdit is overriding the form's
AllowAdditions setting.
Just try....
DoCmd.OpenForm stDocName,,, stLinkCriteria
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."


John Ortt said:
Hi Everyone,

I have designed a form which successfully supresses the ability to create
new records by setting the AllowAdditions property to "No".

The problem is that when I open the form using the code below the form
once again allows additions and I can't figure out how to prevent this.

I tagged the "Me.AllowAdditions = False" into the openargs section but to
no avail.

If anyone can spot the problem in my code I would be very grateful.

Thanks,

John

******* Start Code *******

Private Sub cmdView_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmForm"
stLinkCriteria = "[strIndex]=" & Me.ctlIndex.Value
DoCmd.OpenForm stDocName, ,, stLinkCriteria, acFormEdit, ,
Me.AllowAdditions = False

End Sub

******** End Code ********
 
J

John Ortt

Thanks for the reply Susan

I ended up trying Al's suggestion of removing the "acFormEdit " from the
string used to open the form and this worked perfectly.

My next point of call would have been your suggestion of adding the code to
the onopen event but it wasn't needed.

Thanks for taking the time to help.

All the best,

John



SusanV said:
Hi John,

Put the Me.
AllowAdditions = False line in the On Open argument of the form, rather
than in the sub of the code calling the form.
--
hth,
SusanV


John Ortt said:
Hi Everyone,

I have designed a form which successfully supresses the ability to create
new records by setting the AllowAdditions property to "No".

The problem is that when I open the form using the code below the form
once again allows additions and I can't figure out how to prevent this.

I tagged the "Me.AllowAdditions = False" into the openargs section but to
no avail.

If anyone can spot the problem in my code I would be very grateful.

Thanks,

John

******* Start Code *******

Private Sub cmdView_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmForm"
stLinkCriteria = "[strIndex]=" & Me.ctlIndex.Value
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
Me.AllowAdditions = False

End Sub

******** End Code ********
 
S

SusanV

No problem, glad you got the answer you needed

;-D

John Ortt said:
Thanks for the reply Susan

I ended up trying Al's suggestion of removing the "acFormEdit " from the
string used to open the form and this worked perfectly.

My next point of call would have been your suggestion of adding the code
to the onopen event but it wasn't needed.

Thanks for taking the time to help.

All the best,

John



SusanV said:
Hi John,

Put the Me.
AllowAdditions = False line in the On Open argument of the form, rather
than in the sub of the code calling the form.
--
hth,
SusanV


John Ortt said:
Hi Everyone,

I have designed a form which successfully supresses the ability to
create new records by setting the AllowAdditions property to "No".

The problem is that when I open the form using the code below the form
once again allows additions and I can't figure out how to prevent this.

I tagged the "Me.AllowAdditions = False" into the openargs section but
to no avail.

If anyone can spot the problem in my code I would be very grateful.

Thanks,

John

******* Start Code *******

Private Sub cmdView_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmForm"
stLinkCriteria = "[strIndex]=" & Me.ctlIndex.Value
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
Me.AllowAdditions = False

End Sub

******** End Code ********
 

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

Top