UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Add A New Record Using A Commnad Button And Populate Some Form Fields, Access 2016    
 
   
Vector1
post Dec 22 2017, 03:52 PM
Post#1



Posts: 72
Joined: 9-March 17



Hi,
Can someone help me with this scenario:
I have a form with a command button to open up another form at new record:

DoCmd.OpenForm "_frm_ABR_Endbell", , , , acFormAdd

I would like to populate some common fields from another table and show those populated fields on the form.

(This is needed for record retention)
Go to the top of the page
 
RJD
post Dec 22 2017, 04:12 PM
Post#2


UtterAccess VIP
Posts: 8,948
Joined: 25-October 10
From: Gulf South USA


Hi: Are the fields you want to use to populate the second form controls available from controls on the first for? Or will you have to look them up from some associated table/record (associated by some key?)

If the former, after opening the second form you can, with VBA (start with opening the form), reference the first form by ...

Forms!MySecondForm!SomeField = Forms!MyFirstForm!MyField

...to insert the value.

If the latter, the same as the first option, but use something like either a DLookup ...

Forms!MySeconfForm!SomeField = DLookup("AField]","[ATable]","[MyPK]=" & [PKInSecondForm]

Or, if appropriate, just link to the tables through the query record source for the second table and pull from that.

If I've understood what you are trying to do, some things to consider/try.

HTH
Joe
Go to the top of the page
 
Vector1
post Dec 22 2017, 04:28 PM
Post#3



Posts: 72
Joined: 9-March 17



I ran an append query. The table got populated but the form keeps showing "new" record. The populated records don't show up on the form.
Not sure where do I place "Forms!MySecondForm!SomeField = Forms!MyFirstForm!MyField"
And there is no PK to create a criteria.
Go to the top of the page
 
RJD
post Dec 22 2017, 04:33 PM
Post#4


UtterAccess VIP
Posts: 8,948
Joined: 25-October 10
From: Gulf South USA


You are using acFormAdd in your command. The documentation says that ...

"The user can add new records but can't edit existing records."

Once you append a record, it is an existing record. Have you tried without that part of the command?

And if there is no PK to create a criteria, how do you plan to link to a value in another table? Is it a single-record table?

HTH
Joe
Go to the top of the page
 
Vector1
post Dec 22 2017, 04:58 PM
Post#5



Posts: 72
Joined: 9-March 17



So, what do I use instead of "acFormAdd" to create a new record?
Go to the top of the page
 
Vector1
post Dec 22 2017, 05:15 PM
Post#6



Posts: 72
Joined: 9-March 17



So if I append a record to second form from first form, how do I open the latest appended record
Go to the top of the page
 
Vector1
post Dec 22 2017, 05:18 PM
Post#7



Posts: 72
Joined: 9-March 17



I do have an PK for second form ID (autonumber).
Can I use DMAX to open the last record on the form?
Go to the top of the page
 
Vector1
post Dec 22 2017, 05:31 PM
Post#8



Posts: 72
Joined: 9-March 17



OK...So Got It to work...
Append query
DMax
Openform where condition


Thank you for the help! Your responses made it happen.
Go to the top of the page
 
RJD
post Dec 22 2017, 07:04 PM
Post#9


UtterAccess VIP
Posts: 8,948
Joined: 25-October 10
From: Gulf South USA


Glad you got that sorted! Looks like you actually got that done essentially by yourself, so good going. thumbup.gif

Good luck with your project.

Regards,
Joe
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    21st October 2018 - 09:22 AM