Using rec.seek to avoid upload of multiple duplicate entries

  • Thread starter Marshall P at Falkirk
  • Start date
M

Marshall P at Falkirk

I am using a piece of code to write new codes from a third paty system into
access. The code works fine when a single code is updated, however when more
than one code is selected the routine does not work.

The code I am using is as follows

Private Sub cmdAddSC_Click()
On Error GoTo Err_cmdAddSC_Click
Dim rec As Recordset
Dim strmsg As String
Dim stDocName As String
Set db = CurrentDb()
Set rec = db.OpenRecordset("tblCCBudget")
stDocName = "frmCodeEntry"
DoCmd.OpenForm stDocName
rec.Index = "PrimaryKey"
rec.Seek "=", Forms!frmCodeEntry!Text1
If rec.NoMatch = False Then
MsgBox ("This code already exists")
DoCmd.Close acForm, stDocName
Exit Sub
Else
DoCmd.OpenQuery "qryAddMissingCodesSC"
DoCmd.GoToControl "cmdCloseAddCode"
End If
Exit_cmdAddSC_Click:
Exit Sub

Err_cmdAddSC_Click:
MsgBox Err.Description
Resume Exit_cmdAddSC_Click

End Sub
 
A

Allen Browne

When more than one code is selected?

This looks like the Click event of a command button, so if you mean when
more than one record is selected, the multi-record select will be lost
before the code runs. When you click the button, it takes focus, so the code
will refer to the current record.
 

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