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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open form with blank fields when adding a new record 1

Status
Not open for further replies.

cfvcf

Technical User
Nov 8, 2007
77
US
I have a form that is used to add a new account. The menu form has a "add new acct" button that I have the following code:
Private Sub btn_Add_New_Acct_Click()
On Error GoTo btn_Add_New_Acctt_Click_Err
DoCmd.OpenForm "frm_Organizations_and_Accounts", acNormal, "", "", acAdd, acNormal
DoCmd.Maximize
btn_Add_New_Acct_Click_Exit:
Exit Sub
The form is used to add new acct and also is used to edit existing accts. The first time I open the form using the add new, it the fields are blank. Once I view an existing acct, the next time I click on add new acct, the fields are prefilled with the last one I viewed.

The code I use to open he form is:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err
DoCmd.Requery ""
DoCmd.OpenForm "frm_Organizations_and_Accounts", acNormal, "", _
"[tbl_Orgs]![OrgName]=[Forms]![frm_New_Menu]![combo_Orgs_and_Accounts]", , acNormal
DoCmd.Maximize
Form_Open_Exit:
Exit Sub
Is there some sort of function to clear out the fields when I want to add?
Appreciate your help!
 
Try this on Activate of the form Docmd.GoToRecord acForm, "YourForm", acNewRec
 
Then I have some questions. That form is opened for new accts and existing accts. I thought if the code should be different for the new versus the existing accts, I would code the different code depending on which button they clicked. So wouldn't the activate event for the form that opens for both only add records? Or should I have two totally different forms?

Should I not do the DoCmd.OpenForm in the menu form add new acct click event:
Private Sub btn_Add_New_Acct_Click()
On Error GoTo btn_Add_New_Acctt_Click_Err
DoCmd.OpenForm "frm_Organizations_and_Accounts", acNormal, "", "", acAdd, acNormal

and the code for existing accounts is based off the dropdown list item they selected (combo_Orgs_and_Accounts):
Private Sub combo_Orgs_and_Accounts_Click()
On Error GoTo combo_Orgs_and_Accounts_Click_Err
DoCmd.OpenForm "frm_Organizations_and_Accounts", acNormal, "", _
"[tbl_Orgs]![OrgName]=[Forms]![frm_New_Menu]![combo_Orgs_and_Accounts]", , acNormal
DoCmd.Maximize
combo_Orgs_and_Accounts_Click_Exit:
Exit Sub

Guess I'm confused of the sequence. Thanks!

 
cfvcf,
No, you should be able to use the same form,
cfvcf said:
The first time I open the form using the add new, it the fields are blank. Once I view an existing acct, the next time I click on add new acct, the fields are prefilled with the last one I viewed.

Does [tt]frm_Organizations_and_Accounts[/tt] stay open between button clicks? If so the [tt]acAdd[/tt] doesn't do anything: [tt]DoCmd.OpenForm[/tt] only becomes a fancy way to set the focus to the already open form.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
If you want to go from entering a new record to viewing exisiting records in the same form simply open the form without specifying that it open in AddMode!

DoCmd.OpenForm "frm_Organizations_and_Accounts"

Is there a problem with the user clicking on the standard Access Add Record button that's part of the navigation bar? If so add a button to the form to go to a new record. You can use the Wizard (Record Operations - Add New Record) or simply use this code behind it:

DoCmd.GoToRecord , , acNewRec



The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Bubba100 said:
Try this on Activate of the form Docmd.GoToRecord acForm, "YourForm", acNewRec
I foresee problems with that. For example, user is half-way through entering a new record, decides to check his email, then goes back to the form (which triggers Activate), the record he partially started is automatically saved and a new one pops up.

 

Actually, Activate/Deactivate is only triggered if you move from one object to another within the same application, not when you move from one app to another, but Joe's point is still valid! Of course, all this appears to be moot, as the OP hasn't been back in almost three days now!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks, I closed the frm_Organization_and_Accounts.
 
Thanks for everyone's responses!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top