我已经编写了在表格中添加和编辑数据的代码,但我在条件表达式" 中得到"数据类型不匹配。
Private Sub Submit_Click()
If Me.txtid.Tag & "" = "" Then
'add data to table
CurrentDb.Execute "INSERT INTO Client(Client_ID,Title,First_Name,Last_Name,Employer,DOB,Updated_Date,Email,Phone_Number,Mobile_Number,Address_Street,Date_of_1st_Session,Presenting_Issue,Next_Of_Kin,EAP_Number,Status,History)" & _
" VALUES('" & Me.txtid & "','" & Me.txt_title & "','" & Me.txtname & "','" & Me.txtlastname & "','" & Me.txtorg & "','" & Me.CreatedDate & "','" & Me.UpdatedDate & "','" & Me.txtEmail & "', '" & Me.txtphone & "','" & Me.txtmb & "', '" & Me.txtadd & "','" & Me.txtdate & "', '" & Me.txtissue & "','" & Me.txtnext & "','" & Me.txtEAP & "','" & Me.Combo45 & "','" & Me.txtHistory & "')"
Else
CurrentDb.Execute "UPDATE Client" & " SET Client_ID=" & Me.txtid & ", Title='" & Me.txt_title & "'" & ", First_Name='" & Me.txtname & "'" & ", Last_Name='" & Me.txtlastname & "'" & ", Employer='" & Me.txtorg & "'" & ", DOB='" & Me.CreatedDate & "'" & ", Updated_Date='" & Me.UpdatedDate & "'" & ", Email='" & Me.txtEmail & "'" & ", Phone_Number='" & Me.txtphone & "'" & ", Mobile_Number='" & Me.txtmb & "'" & ", Address_Street='" & Me.txtadd & "'" & ", Date_of_1st_Session='" & Me.txtdate & "'" & ", Presenting_Issue='" & Me.txtissue & "'" & ", Next_Of_Kin='" & Me.txtnext & "'" & ", EAP_Number='" & Me.txtEAP & "'" & ", Status='" & Me.Combo45 & "'" & ", History='" & Me.txtHistory & "'" & " WHERE Client_ID=" & Me.txtid.Tag
End If
Command39_Click
Me.txtid.SetFocus
Client_subform.Form.Requery
End Sub
答案 0 :(得分:0)
当某些数据项可能是数字或日期时,您似乎将所有值都视为字符串('"& Me.txtid&"')。 如果它是数字或(#"& Me.CreatedDate&"#)
,请尝试("& Me.txtid&")