Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Open Status: acFormAdd or acFormEdit

Status
Not open for further replies.

joatmofn

Technical User
Jan 12, 2003
72
0
0
US
I am using "DoCmd.OpenForm stDocName, , , , acForm[Add/Edit]" to open a form.

During the load process of the form, I need to check the form to see if it was opened using acFormAdd or acFormEdit. Any ideas?

Thanks.
 
Not sure I understand why you need this, surely you are able to tell which command is used in your own code, unless the same peice of code contains the both and is dependant on some parameter. In which case maybe set a variable to one of two values depending on which code is executed.
 
Yes, I already thought about using a variable. It would be less house-keeping to check the status of the form, however.

The reason for checking whether the form was opened in new or edit mode is to make certain controls visible and other controls locked.

As an example, when the form is opened acFormNew, then some of the form's controls are visible = false. On the other hand, when the form is opened acFormEdit, the controls that are not visible are changed to visible. Also other controls on the form (in acFormEdit) mode will have their property for locked set to yes.

Does this help? Any ideas?

Thanks.
 
Perhaps you could use the openargs parameter of the docmd.openform command. Pass different arguments to the called form with each docmd.openform. That way your code in the called form can take appropriate actions depending on the argument passed.

HTH.
 
Hmmm... have you tried setting the values based on the Primary key's value? If the form opens a new record your primary key should be a null value (because its new). So on your form's "On Current" event you could run something like this:

If IsNull(Me!PrimaryKeyFieldName) Then
Me!TextBox1.Visible = False
Me!TextBox2.Visible = False
Else
Me!TextBox1.Visible = True
Me!TextBox2.Visible = True
End If

If you need to show these controls at somepoint when the record is being typed in then you would set the controls' visibility properties on another textbox's "After Update" event.

But thats just my 2 cents worth...

jbehrne

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Yep, I already considered openargs. But again, I am hoping that a forms property exists that I could check. I haven't ruled out the use of openargs, however.
 
I like the idea of checking the primary key. I'm gonna try it and the openargs and decide which works best with our application. Thanks to all who posted in this thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top