Adding records

  • Thread starter Thread starter Guest
  • Start date Start date
I am trying to add a new record to a table in a subform.
How do you do it in code?

What's the context? Where do you want the code to reside - on the
subform, on the mainform? Where will the code get the data to be
added?

In short, you could use code like

Me!subformname.SetFocus
DoCmd.GoToRecord,,acNewRecord
Me!controlname = somevalue
 
I am building an IT helpdesk database, and I want to add a New Record in a subform (subActions) of the main form (fpriINCIDENTS), from another open form (frmHELPFILE)

A copy of the ID number of the record selected in form frmHELPFILE, (this has an underlying table tblHELPFILE that containes a list of troubleshooting tips) through a command button click event, will be transfered to the new record on the subform (subActions). Thus maintaining a list of tried troubleshooting tips for each incident. Therefore the code resides on a serparate form from either the main or subforms

If an excisting record in the subform of the main form is the focus the

strAddHelp = Me![txtHelpFileID].Valu
Forms!fpriINCIDENTS!subActions!cboHelpFileID = strAddHel

copies the data across and replaces what is already there, but I need a way of making the new record the focus, just before the ID number is copied, and then the record is save. Therefore completing the operation

Regard
Shau
 
copies the data across and replaces what is already there, but I need a way of making the new record the focus, just before the ID number is copied, and then the record is save. Therefore completing the operation.

Set focus to the subform and use

DoCmd.GoToRecord, , acNewRecord

before setting the value of the control.
 
What is the syntax for settting the focus to a subform (subActions) on the main form (fpriINCIDENTS)
I keep getting 'Cant got specific record' if i us

Forms!fpriINCIDENTS!subActions.SetFocu

----- John Vinson wrote: ----

On Tue, 2 Mar 2004 04:06:08 -0800, Shaun Jorda
copies the data across and replaces what is already there, but I need a way of making the new record the focus, just before the ID number is copied, and then the record is save. Therefore completing the operation

Set focus to the subform and us

DoCmd.GoToRecord, , acNewRecor

before setting the value of the control

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=publi
 
What is the syntax for settting the focus to a subform (subActions) on the main form (fpriINCIDENTS)?
I keep getting 'Cant got specific record' if i use

Forms!fpriINCIDENTS!subActions.SetFocus

I think you may need to set focus to the subform and *then* to a
particular control on the subform. If you're calling the code from the
mainform, use

Me!subActions.SetFocus
Me!subActions.Form!somecontrol.SetFocus

Note that subActions is the name *of the Subform control*, which may
or may not be the same as the name of the Form in that control.
 
Regarding the error 2105, you need to requery the object before you ca
add a new record:

Me.Requery
DoCmd.GoToRecord , , acNewRec

Hope this helps,
Susann
 
Regarding the error 2105, you need to requery the object before you ca
add a new record:

Me.Requery
DoCmd.GoToRecord , , acNewRec

Hope this helps,
Susann
 
Back
Top