command button - add record

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!
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top