MS Access - Form - Open new form with previous form IF for Edit Record

Hey,

I have a form in which user search for record, this form have a subform which is a datasheet  in which the required search show up. Then there is a button as Edit Record which open new form for editing. I have 9 fields in subform, when user select record and click edit button the new form which open up shows the previous 8 fields except one field "ID" which is always opening as a new record, i want the ID to be  from the previous form not the new record. I have set Data Entry to be Yes which is required in my form, is there a way to get ID from previous form with data entry to yes.

Any help would be appreciated.

Thank you.
LVL 1
WSStudentAsked:
Who is Participating?
 
mbizupCommented:
Is there a particular reason you need the Data Entry property to be 'Yes'?  If Data Entry is set to 'Yes', the form will open for the user to enter NEW records which as Anders said, will display NEW for the AutoNumber ID as they are created:

Data Entry Property

If you want to open a form to edit an EXISTING record, you would use a Where Condition when opening the form in VBA, with the DataEntry property set to No:

DoCmd.OpenForm "YourFormName", WhereCondition := "ID = " & Me.YourIDFieldName

Open in new window

0
 
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
As you open the form, pass in the ID you want to use, as an OpenArgs
docmd.OpenForm "frm_name",,,,acFormAdd,,me.ID

Open in new window


In the LOAD even of your form, you then read the OpenArgs.
Private Sub Form_Load()
  me.SomeTextbox.DefaultValue=Me.OpenArgs
end Sub

Open in new window


Note that if your form is allready open in design mode (because you are busy designing) then the OpenArgs will not work. So if you make changes to your form, make sure to close it fully before testing.
0
 
WSStudentAuthor Commented:
It's not working, any idea why? still it show id as new .
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
If it shows ID as new, it is because the field is bound to an AUTONUMBER field, where you can't assign ID's through the GUI interface.
0
 
WSStudentAuthor Commented:
yes it is an autonumber field , isn't it possible through VBA? what if i put Data entry to no?
0
 
WSStudentAuthor Commented:
i just want to open it to Data Entry form so that i could get values for all the fields from previous form. I am using Default Value property for 8 fields and if i turn Data Entry to No it doesn't work. that's the only reason behind this.
0
 
WSStudentAuthor Commented:
Thank you everyone :)

i turn off the Data Entry property and for ID i use the code mark as best solution with the rest field using Default Values from previous form.

Thanks again.
0
 
mbizupCommented:
Humm.... Test that a bit to make sure it is really what you are looking for (I'm not 100% clear on your goal here).  If you are actually trying to 'Copy an existing record to a new record', there are plenty of examples on the web.  If you still need assistance, you can use the 'report question' button to ask a moderator to reopen the question.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.