2017-07-31 67 views
0

我正在尝试为员工创建一个表单,以便为预约输入疏导时间。为什么不允许更新新记录

以为我有它的工作,直到相同的宠物约会新的日期,然后我得到一个Microsoft Visual Basic运行时错误3022,并不会添加新条目。

我在哪里想念这里发生了什么?

Private Sub cmdNew_Click() 

' Error check for empty comboboxes 
If IsNull(CmbPetName) = True Then 
    MsgBox ("Pick A Pet For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbPEmplye) = True Then 
    MsgBox ("Pick A Prep Employee For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbPTime) = True Then 
    MsgBox ("Pick A Prep Time For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbBEmplye) = True Then 
    MsgBox ("Pick A Bath Employee For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbBTime) = True Then 
    MsgBox ("Pick A Bath Time For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbDEmplye) = True Then 
    MsgBox ("Pick A Dry Employee For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbDTime) = True Then 
    MsgBox ("Pick A Dry Time For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbGEmplye) = True Then 
    MsgBox ("Pick A Groom Employee For This Operation") 
    Exit Sub 
ElseIf IsNull(CmbGTime) = True Then 
    MsgBox ("Pick A Groom Time For This Operation") 
    Exit Sub 
End If 

'Set variables for error checking duplicates 
Dim pid As String 
Dim aptdate As Date 
pid = CmbPetName.Column(2) 
    'MsgBox (pid) 
aptdate = txtAptDate.Value 
    'MsgBox (aptdate) 
Dim strCriteria As String 

'Set Criteria for DCount() 
strCriteria = "([PetID] = '" & pid & "') And ([ApptDate] = #" & aptdate & "#)" 
    'MsgBox (strCriteria) 

'Error checking for duplicates 
If DCount("[PetID]", "[TimeLog]", strCriteria) > 0 Then 
    MsgBox ("Record Already Exists") 
    Exit Sub 
End If 

'Set variables to record entries 
Dim rs As DAO.Recordset 
Dim db As DAO.Database 
Set db = CurrentDb 
Set rs = db.OpenRecordset("TimeLog", dbOpenTable) 

'Add entries to Table TimeLog 
rs.AddNew 
rs!PetID = CmbPetName.Value 
rs!PetName = Me.CmbPetName.Column(0) 
rs!ApptDate = txtAptDate.Value 
rs!ptime = CmbPTime.Value 
rs!PEmplyee = CmbPEmplye.Value 
rs!btime = CmbBTime.Value 
rs!BEmplyee = CmbBEmplye.Value 
rs!dtime = CmbDTime.Value 
rs!DEmplyee = CmbDEmplye.Value 
rs!gtime = CmbGTime.Value 
rs!GEmplyee = CmbGEmplye.Value 

rs.Update 

rs.Close 
db.Close 

Set rs = Nothing 
Set db = Nothing 

Me.CmbPetName = Null 
Me.CmbPEmplye = Null 
Me.CmbBEmplye = Null 
Me.CmbDEmplye = Null 
Me.CmbGEmplye = Null 
Me.CmbPTime = Null 
Me.CmbBTime = Null 
Me.CmbDTime = Null 
Me.CmbGTime = Null 

End Sub 

运行时发生在rs.update行上。

+0

错误信息的*文本*是什么? –

回答

1

这张桌子上的主要关键是什么?从它的声音,你的主键可能只是在宠物上,而不是在宠物预约日期的复合键。

+0

有种感觉就像一个dumba $$现在大声笑,不知何故我的PK是在PetID而不是自动编号。谢谢你的明显! –

+0

:)不用担心。发生在我们身上。 –

0

rs!PetID = CmbPetName.Value无法复制可能产生冲突的密钥?