Insert Command

  • Thread starter Thread starter Kevin Sprinkel
  • Start date Start date
K

Kevin Sprinkel

I have been using the following code in a NotInList
procedure to insert a new record into a table, and then
open a data entry form by the linking criteria. In this
case, JobNumber is the primary key.

strfql = "Insert Into tblProjects([JobNumber]) values ('"
& NewData & "')"
CurrentDb.Execute strsql, dbFailOnError
strLinkCriteria="[JobNumber]=&NewData & "' "
DoCmd.OpenForm strFrmName,,,strLinkCriteria
Response = acDataErrAdded

I would like some help adapting this general strategy to a
different situation. This time, the primary key is an
AutoNumber field, and I would like to set the value of two
fields in the inserted record--one to the NewData that
wasn't in the list, and the value from another combo box
on the form.

In detail, the target table is:

SteelSizes
==========
SteelSizeID AutoNumber
SteelType Number, FK to SteelTypes
SteelSize Text consisting of dimensions, e.g., 4x8x1/2
LBperLF Number (Pounds per lineal foot)
SFperLF Number (Square feet of surface area per LF)

and I would like NewData to go to [SteelSize] and the
value of cboSteelType to go to [SteelType] when the form
opens.

Thanks for all help.
Kevin Sprinkel
 
-----Original Message-----
I have been using the following code in a NotInList
procedure to insert a new record into a table, and then
open a data entry form by the linking criteria. In this
case, JobNumber is the primary key.

strfql = "Insert Into tblProjects([JobNumber]) values ('"
& NewData & "')"
CurrentDb.Execute strsql, dbFailOnError
strLinkCriteria="[JobNumber]=&NewData & "' "
DoCmd.OpenForm strFrmName,,,strLinkCriteria
Response = acDataErrAdded

I would like some help adapting this general strategy to a
different situation. This time, the primary key is an
AutoNumber field, and I would like to set the value of two
fields in the inserted record--one to the NewData that
wasn't in the list, and the value from another combo box
on the form.

In detail, the target table is:

SteelSizes
==========
SteelSizeID AutoNumber
SteelType Number, FK to SteelTypes
SteelSize Text consisting of dimensions, e.g., 4x8x1/2
LBperLF Number (Pounds per lineal foot)
SFperLF Number (Square feet of surface area per LF)

and I would like NewData to go to [SteelSize] and the
value of cboSteelType to go to [SteelType] when the form
opens.

Thanks for all help.
Kevin Sprinkel
.
 
Back
Top