There are a couple of ways to accomplish what you want to do.
Just to make sure I understand, you have a form "Asset Condition Scoring" (frmInput) with a button ("Defects Info") on each record that, when clicked, should open a 2nd form "Asset Defects and Remedial Works" (frmASSET_WORKS) to add additional detail records.
First Method:
Insert a new record into the table for "frmASSET_WORKS", then open the form with the same syntax as above. The code for the button would look something like:
Code:
Private Sub btnAddDefects_Click()
On Error GoTo Err_btnAddDefects_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim sSQL As String
'create a new record in the "frmASSET_WORKS" table
sSQL = "INSERT INTO tblAssettDefects (Asset_ID, Criteria_ID) VALUES ('" & Me.[Asset_ID] & "', " & Me.[Criteria_ID] & ");"
CurrentDb.Execute sSQL, dbFailOnError
'open the form to the new record
stLinkCriteria = "[Asset_ID] = '" & Me.[Asset_ID] & "' AND [Criteria_ID] = " & Me.[Criteria_ID]
DoCmd.OpenForm "frmASSET_WORKS", , , stLinkCriteria
Exit_btnAddDefects_Click:
Exit Sub
Err_btnAddDefects_Click:
MsgBox Err.Description
Resume Exit_btnAddDefects_Click
End Sub
------------------------------
Another method is to open the form then create the new record. When opening the form, the command string would use the "Open Arguments" clause.
The button code remains essentially the same.....but there is more code.
The code for the button:
Code:
Private Sub btnAddDefects_Click()
On Error GoTo Err_btnAddDefects_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim sSQL As String
'create a new record in the "frmASSET_WORKS" table
' sSQL = "INSERT INTO tblAssettDefects (Asset_ID, Criteria_ID) VALUES ('" & Me.[Asset_ID] & "', " & Me.[Criteria_ID] & ");"
' CurrentDb.Execute sSQL, dbFailOnError
'open the form to the new record
If IsNull(Me.[Asset_ID]) Or IsNull(Me.[Criteria_ID]) Then
Else
stLinkCriteria = Me.[Asset_ID] & " | " & Me.[Criteria_ID]
End If
DoCmd.OpenForm "frmASSET_WORKS", OpenArgs:=stLinkCriteria
Exit_btnAddDefects_Click:
Exit Sub
Err_btnAddDefects_Click:
Select Case Err.Number
Case 2501
Case Else
MsgBox Err.Description & " Err Number: " & Err.Number
End Select
Resume Exit_btnAddDefects_Click
End Sub
The code for the form "frmASSET_WORKS":
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_FormOpen
Dim arData
If IsNull(OpenArgs) Then
MsgBox "Missing data for " & vbNewLine & vbNewLine & "[Asset_ID] or Criteria_ID"
Cancel = True
Else
'put the data into the array
arData = Split(OpenArgs, "|")
' fill the controls from the array
Me.[Asset_ID] = arData(0)
Me.[Criteria_ID] = arData(1)
End If
Exit_FormOpen:
Exit Sub
Err_FormOpen:
MsgBox Err.Description
Resume Exit_FormOpen
End Sub
The form "frmASSET_WORKS" should have the properties:
Data Entry = Yes
Modal = Yes
Be sure and change the table, control and form names to your names. I had to guess on a couple of the names.
Hope I put in enough comments..