我試圖在MS Access窗體上創建添加,更新,刪除操作。我在互聯網上發現了這個代碼,其中插入和更新發生在同一個按鈕上。我沒有得到下面發生的事情,以及它是如何識別更新或插入的。MS Access Tag屬性 - 如何識別更新和插入操作?
沒有得到以下行:= Me.txtid.Tag &「」 =「」
請在下面找到它完美的作品按規定的代碼。
「當我們點擊按鈕添加有兩種選擇
'1. for insert
'2. for update
If Me.txtid.Tag & "" = "" Then
' this is for insert new
' add data in table
CurrentDb.Execute "insert into student(stdid,stdname,gender,phone,address)" & _
" values(" & Me.txtid & ",' " & Me.txtname & " ',' " & Me.cmbgender & " ','" & _
Me.txtphone & "', '" & Me.txtaddress & "')"
'refresh data in list on form
subform_student.Form.Requery
否則
CurrentDb.Execute "UPDATE student " & _
" set stdid = " & Me.txtid & _
", stdname = '" & Me.txtname & "' " & _
", gender = '" & Me.cmbgender & " ' " & _
", phone = ' " & Me.txtphone & " ' " & _
", address = ' " & Me.txtphone & " ' " & _
" WHERE stdid = " & Me.txtid.Tag
結束如果
答案是完全有說服力的。感謝您的回覆:) – user3172930