Form Name = frm_EDI_LOG) – form is Unbound
Here are the field names and associated control names:
TABLE NAME FIELD NAME
HEALTHPLAN (Text) cboHP
CLIENT (Text) CLIENT_LIST
FILE_MONTH (Text) cboFile_Month
FILE_WEEK (Text) cboFile_Week
FILE_DATE (Short Date) txtFile_Date
Here is the code I have behind the Save Records button.
(All of the other code works when I remove the Validation Code)
I need to use all 5 fields as validation (although Report Week and/or Report Date can be null)
I tried to do this just with 2 fields as a test, but I would guess some of my single/double quotes are messing me up.
I need help with the DCount
Code: Select all
Private Sub SAVE_RECS_Click()
Dim varItem As Variant
Dim strSQL As String
Dim db As Database
Dim rec As Recordset
For Each varItem In Me.CLIENT_LIST.ItemsSelected
If DCount("'" & " And " & "[HEALTHPLAN] = " & "'" & Me.cbo_HP & "*", "tblEDI_LOG", "[CLIENT] = " & "'" & Me.CLIENT_LIST.ItemData(varItem)) > 0 Then
MsgBox "A record already exists for one or more of the records you are trying to add on the requested date, the records will not be saved."
DoCmd.CancelEvent
Exit Sub
Else: End If
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from [tblEDI_LOG]")
rec.AddNew
rec("CLIENT") = Me.CLIENT_LIST.ItemData(varItem)
rec("Healthplan") = Me.cbo_HP
rec("FILE_month") = Me.cboFile_Month
rec("FILE_week") = Me.cboFile_Week
rec("FILE_date") = Me.txtFile_Date
rec("TIME_STAMP") = Now
rec.Update
Set rec = Nothing
Set db = Nothing
Next varItem
End Sub
Michael