Data entry code VS two forms

A

Aaron G

Using Access 2003-

I have a popup that I want to use to add new records. I also want to use it
to review old records. I would use a command button to open each. One would
say "ADD" and the other would be "EDIT". Should I...

1-Create a line of code that when I click the "ADD" button sets the data
entry variable to true, and if so, how do I do that?

2-Use two nearly identical forms where one has the data entry variable set
to true and the other to false? This seems like I'm bloating my db for no
reason. Is this more stable?

TIA

Aaron G
Philadelphia, PA
 
D

Dirk Goldgar

Aaron G said:
Using Access 2003-

I have a popup that I want to use to add new records. I also want to
use it to review old records. I would use a command button to open
each. One would say "ADD" and the other would be "EDIT". Should I...

1-Create a line of code that when I click the "ADD" button sets the
data entry variable to true, and if so, how do I do that?

2-Use two nearly identical forms where one has the data entry
variable set to true and the other to false? This seems like I'm
bloating my db for no reason. Is this more stable?

I'd use one form, and pass it an argument of either "ADD:" or "EDIT" via
the OpenArgs argument of the call to DoCmd.OpenForm that I use to open
the form. Then I'd have code in the form's Open event that sets the
form's DataEntry property to True if the argument "ADD" was passed.

'----- begin code for form's Open event -----
Private Sub Form_Open(Cancel As Integer)

Select Case Me.OpenArgs & vbNullString
Case "ADD": Me.DataEntry = True
Case "EDIT": Me.DataEntry = False
Case Else ' leave design setting unchanged
End Select

End Sub
'----- end code for form's Open event -----

Code for Add button:

DoCmd.OpenForm "MyFormName", OpenArgs:="ADD"

Code for Edit button:

DoCmd.OpenForm "MyFormName", OpenArgs:="EDIT"
 
A

Aaron G

Dirk,

Thanks for all your help today. While I was waiting for a response, I added
the "DataEntry=True" argument to the DataMode section of my DoCmd.OpenForm
line. This seems to solve the problem. However, I'm very interested in your
process. Does your method provide more stability? Less bloat?

Thanks again, and have a great weekend.

Aaron G
Philadelphia, PA
 
D

Dirk Goldgar

Aaron G said:
Dirk,

Thanks for all your help today. While I was waiting for a response,
I added the "DataEntry=True" argument to the DataMode section of my
DoCmd.OpenForm line. This seems to solve the problem. However, I'm
very interested in your process. Does your method provide more
stability? Less bloat?

"DataEntry=True"? Do you mean

DoCmd.OpenForm "YourFormName", DataMode:=acFormAdd

? If so, that's actually the best way to do it if you want to make this
simple distinction, and I should have thought of that first off. <sigh>
I'm just too code-oriented sometimes. On the other hand, if you wanted
to do more context-based tweaking of your form, depending on whether
it's being opened for editing or for data entry, then the OpenArgs/Open
event approach I suggested would be more powerful and flexible. But
just to determine data-entry mode vs. edit mode, the DataMode argument
is simplest and best, and I must apologize for not suggesting it in the
first place.
 
Top