如何从msgbox中的访问表中获取特定的id

时间:2014-01-13 10:04:06

标签: vba ms-access access-vba

我想获得特定记录的ID

这是我的代码

If DLookup("Full_Name", "tbl_Personal_Information", "Full_Name = Forms!frm_New_Person!F_N") > 0 Then
MSG = MsgBox("this person is existed and his id number is {" & [P_ID] & "} ", vbOKOnly + vbInformation + vbMsgBoxRtlReading, "client database")
Else
strsql101 = "insert into tbl_Personal_Information (Name_English, Father_English, Family_English, Mother_English, P_ID, NName, Father, Family, Mother, Birthdate, Nationality, Record_Number, Record_Place, Address, Mobile1, Mobile2, Phone1, Phone2, Ets_Name) Values ('" & Me.Name_English & "','" & Me.Father_English & "','" & Me.Family_English & "','" & Me.Mother_English & "','" & Me.PID & "','" & Me.NName & "','" & Me.Father & "','" & Me.Family & "','" & Me.Mother & "','" & Me.Birthdate & "','" & Me.Nationality & "','" & Me.Record_Number & "','" & Me.Record_Place & "','" & Me.Address & "','" & Me.Mobile_1 & "', '" & Me.Mobile_2 & "','" & Me.Phone_1 & "', '" & Me.Phone_2 & "','" & Me.Ets_Name & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql101
MSG = MsgBox("information added", vbOKOnly + vbInformation + vbMsgBoxRtlReading, "client database")

一切正常,但msgbox中的id给了我表格中的最后一个ID

1 个答案:

答案 0 :(得分:1)

看起来你没有查找你想要的记录的P_ID。

你应该做这样的事吗?

  MSG = MsgBox("this person is existed and his id number is {" & DLookup("[P_ID]", "tbl_Personal_Information", "Full_Name = Forms!frm_New_Person!F_N") & "} ", vbOKOnly + vbInformation + vbMsgBoxRtlReading, "client database")