command button - add record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use a button to open a form and filter to a record:

Private Sub cmdopenfgprocessing_Click()
On Error GoTo Err_cmdopenfgprocessing_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sfrmFGProcessing"

stLinkCriteria = "[txtProfileID]=" & "'" & Me![cbProfileID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdopenfgprocessing_Click:
Exit Sub

Err_cmdopenfgprocessing_Click:
MsgBox Err.Description
Resume Exit_cmdopenfgprocessing_Click

End Sub

This works fine as long as there is an existing record in the table
tblFGProcessing.txtProfileID which is the record source for sfrmFGProcessing.

How can I keep the button's current function and add a function to create a
record in tblFGProcessing.txtProfileID if one doesn't exist?

Thanks!
 
Do a DLOOKUP to search for an existing record before doing the OpenForm.
If you find it, proceed as now otherwise do:
docmd.OpenForm,,,,acFormAdd

Dorian
 
Back
Top