Check if form is opened for edit or add (1 Viewer)

RexesOperator

Registered User.
Local time
Today, 05:26
Joined
Jul 15, 2006
Messages
604
I would like to set the properties of a control on a form based on if it is opened in edit or add mode.

For example I use one form for both editing and adding records (the mode is changed based on the command button that calls it). I have a command button on the form for searching records I created using the command button wizard. It's kind of pointless to have it active when there is no data to search for.

I'd like to have the form opened in add mode with the button either not enabled or not visible, but in edit mode have the button enabled or visible.

This isn't essential, but it would be nice to have.

I know one option is to have the form opened by DoCmd.OpenForm, but how would I control the add/edit mode using DoCmd?
 

John Big Booty

AWF VIP
Local time
Today, 19:26
Joined
Aug 29, 2005
Messages
8,263
You can use the DataMode portion of the Docmd to tell the form in general how to open or if you wish to be more specific use the OpenArgs of the DoCmd to pass info to the form being opened. You can then test the OpenArgs in the on load event of the form being opened, and set the various on form control Add/Edit properties accordingly.
 

RexesOperator

Registered User.
Local time
Today, 05:26
Joined
Jul 15, 2006
Messages
604
Thank you - the DeCmd works perfectly!
 

esskaykay

Registered User.
Local time
Today, 10:26
Joined
Mar 8, 2003
Messages
267
I too think this is what I'm looking for. I would like to test if a form is opened in ADD or ReadOnly, then perform select operations accordingly -- something like:

If form in EDIT then
do this
Else
do that
end if


Thanks,
SKK
 

John Big Booty

AWF VIP
Local time
Today, 19:26
Joined
Aug 29, 2005
Messages
8,263
Try something like;

Code:
If Me.AllowEdits = True Then 
     Do some action
Else
     Do something else
End If
 

esskaykay

Registered User.
Local time
Today, 10:26
Joined
Mar 8, 2003
Messages
267
Ahh pretty simple -- thank you.

This will work for most cases but what if I want to test if the form is in ADD (new record)/ Is there a way to test for ADD, ReadOnly, etc.

SKK
 

esskaykay

Registered User.
Local time
Today, 10:26
Joined
Mar 8, 2003
Messages
267
I think I answered my question

If Me.NewRecord = True Then

Thanks again,
SKK
 

wazz

Super Moderator
Local time
Today, 17:26
Joined
Jun 29, 2004
Messages
1,711
use
If Me.DataEntry Then ...
to test for Add mode.
 

GrunleStan

Registered User.
Local time
Today, 17:26
Joined
Aug 7, 2018
Messages
22
apologies for reopening this old Thread,
but if I were to test for a form to be open as Read only, what would I test for ?

me.allowedits ?
 

Users who are viewing this thread

Top Bottom