I have a popup input form that I am using to accomplish 2 separate tasks. When viewing an RMA, a user can input new or edit an existing labor entry. There's a button on the RMA form that allows them to enter new, and there's an edit hyperlink with a click event for each entry that allows the editing of that record only. If the user clicks either of these one form is loaded as a pop up with either the record being edited or an essentially blank form with a new ID for the associated table. The edit functionality works great, no problems there. When a new entry is created, it doesn't actually create an entry in the table, so something somewhere is not being saved. Here's my code:
For the New Entry button:
For the Edit Entry button
And here's the on_open event for the popup form
For the New Entry button:
Code:
Private Sub cmdNewLaborEntry_Click()
'Set to openargs to NEW, and open form
Dim strOpenArgs As String
strOpenArgs = "NEW|" & txtRMA.Value
DoCmd.OpenForm "frmChangeLaborEntry", acNormal, , , acFormAdd, , strOpenArgs
End Sub
For the Edit Entry button
Code:
Private Sub txtEditLink_Click()
'Grab the ID value, Set to openargs, and open form
DoCmd.OpenForm "frmChangeLaborEntry", acNormal, OpenArgs:=Me.txtID.Value
End Sub
And here's the on_open event for the popup form
Code:
Private Sub Form_Open(Cancel As Integer)
'Check for openargs
If IsNull(Me.OpenArgs) Then
MsgBox "Openargs is null. No data loaded. Now closing form."
DoCmd.Close acForm, "frmChangeLaborEntry", acSaveNo
End
End If
Dim strSQLGetID As String
Dim strOpenArgs As String
strOpenArgs = Me.OpenArgs
'If OpenArgs is numeric:
If IsNumeric(strOpenArgs) Then
Dim intRecordID As Integer
intRecordID = strOpenArgs
strSQLGetID = "SELECT * FROM tblRMALabor WHERE ID = " & intRecordID & ";"
Me.RecordSource = strSQLGetID
'If OpenArgs begins with "NEW|"
ElseIf Left(strOpenArgs, 4) = "NEW|" Then
strSQLGetID = "SELECT * FROM tblRMALabor;"
Me.RecordSource = strSQLGetID
txtRMA.Value = Mid(strOpenArgs, 5, Len(strOpenArgs))
'Does not fit above criteria
Else
MsgBox "Openargs is not formatted correctly." & vbCrLf & _
"Me.OpenArgs read in as: " & Me.OpenArgs & vbCrLf & _
"Ending macro and closing form."
DoCmd.Close acForm, "frmChangeLaborEntry", acSaveNo
End If
End Sub