Hello,
I'm developing a database where workinstruction s (which consist of Steps) can be created and edited. I'v already completed the "Create" form and it works flawless. Now I'm stuck on the Edit part. The user must be able to select a Step and the data from the already created Step must appear on the Edit form. When the user is finished with editting, the data must be saved in a new record. The old data may not be overwritten because the old data always has to be accessible.
I have a bound form (EditStep) with:
Form: EditStep
RecordSource: tblSteps
Textbox: txtStepName
CtrlSource: StepName
Textbox: subStepBox
CtrlSource: Unbound
Button: cmdEditStep
Button: cmdSelectStep3
(If this button is pressed, the dialog form "SelectStep " will be opened.)
Form: SelectStep
Record Source: Unbound
This Form (SelectStep) has also a button "Select Step" and a List (selectionList) . After the user selects a list item and presses the Select Step button, the StepID value from the list is set to the textbox "subStepBox ".
Button: cmdSelectStep
List: selectionList
Row Source: SELECT tblSteps.StepID FROM tblSteps
The main form also has a continuous form:
Continuous subform: subForm1
Link Master Field: subStepBox
Link Child Field: StepID
The subform (subForm1) consists of two Controls:
Textbox: Qty
CtrlSource: Qty
Combobox: cboPart
Control Source: PartID
RowSource: SELECT tblParts.partID , tblParts.PartDe scription FROM tblParts ORDER BY tblParts.PartDe scription
In my database the following tables exist:
Table: tblParts
PartID (Primary Key)
PartDescription (text)
Table: tblSteps
StepID (Primary Key)
StepName (text)
Table: tblStepParts
StepPartID (Primary Key)
StepID (number)
PartID (number)
Qty (number)
This is my working code for setting the EditStep form to the selected record:
The code for the Edit Step button is simple:
If the User selects a step the data is correctly shown in the Controls on the forms. If the user edits something on the mainform (EditStep) for instance, the StepName, this edit is saved succesfully under a new record with a new StepID. However, if the User edits something on the continious subform (Qty or PartID) and then clicks the Edit Step button, the data Qty and/or PartID from the selected (original) step is adjusted. These data isn't saved to a new record.
I need something to duplicate the values in tblStepParts to new records in the same table but with the StepID adjusted to the current record of the main form.
I hope someone can chime in and provide some help.
Kind regards,
Jeroen
I'm developing a database where workinstruction s (which consist of Steps) can be created and edited. I'v already completed the "Create" form and it works flawless. Now I'm stuck on the Edit part. The user must be able to select a Step and the data from the already created Step must appear on the Edit form. When the user is finished with editting, the data must be saved in a new record. The old data may not be overwritten because the old data always has to be accessible.
I have a bound form (EditStep) with:
Form: EditStep
RecordSource: tblSteps
Textbox: txtStepName
CtrlSource: StepName
Textbox: subStepBox
CtrlSource: Unbound
Button: cmdEditStep
Button: cmdSelectStep3
(If this button is pressed, the dialog form "SelectStep " will be opened.)
Form: SelectStep
Record Source: Unbound
This Form (SelectStep) has also a button "Select Step" and a List (selectionList) . After the user selects a list item and presses the Select Step button, the StepID value from the list is set to the textbox "subStepBox ".
Button: cmdSelectStep
List: selectionList
Row Source: SELECT tblSteps.StepID FROM tblSteps
The main form also has a continuous form:
Continuous subform: subForm1
Link Master Field: subStepBox
Link Child Field: StepID
The subform (subForm1) consists of two Controls:
Textbox: Qty
CtrlSource: Qty
Combobox: cboPart
Control Source: PartID
RowSource: SELECT tblParts.partID , tblParts.PartDe scription FROM tblParts ORDER BY tblParts.PartDe scription
In my database the following tables exist:
Table: tblParts
PartID (Primary Key)
PartDescription (text)
Table: tblSteps
StepID (Primary Key)
StepName (text)
Table: tblStepParts
StepPartID (Primary Key)
StepID (number)
PartID (number)
Qty (number)
This is my working code for setting the EditStep form to the selected record:
Code:
Private Sub cmdSelectStep_Click()
On Error Resume Next
Dim rst As Object
Set rst = Forms!EditStep.Form.RecordsetClone
rst.FindFirst "StepID = " & Me.selectionList.Value
Forms!EditStep.Form.Bookmark = rst.Bookmark
DoCmd.Close
RunCommand acCmdRecordsGoToNew
End Sub
Code:
On Error Resume Next
If (Form.Dirty) Then
DoCmd.RunCommand acCmdSaveRecord
End If
DoCmd.GoToRecord , "", acNewRec
MsgBox "Step created Succesfully!", vbInformation, ""
I need something to duplicate the values in tblStepParts to new records in the same table but with the StepID adjusted to the current record of the main form.
I hope someone can chime in and provide some help.
Kind regards,
Jeroen
Comment