更新按钮没有完全工作 [英] Update Button not Fully Working

查看:136
本文介绍了更新按钮没有完全工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制定出了这种形式的问题,一个星期左右现在已经差不多到了一个解决方案,但我撞到南墙。我有一个大的形式有多种功能,功能之一就是编辑子窗体,里面的codeS等各种数据的列表。当我点击编辑按钮自动填充选定的数据框。该功能的工作原理,当我点击更新按钮,但是当我点击保存按钮,它实际上并没有保存数据。在code是:

私人小组cmdEdit_Click() 检查是否存在列表中的数据 如果不是(Me.TableSub.Form.Recordset.EOF而Me.TableSub.Form.Recordset.BOF)然后 获取的数据文本框控件 随着Me.TableSub.Form.Recordset     Me.text_key =点域(KW)     Me.txt_ code =点域(code)     Me.combo_source =点域(源)     存储学生ID在文本的ID标签的情况下,ID被修改     Me.txt_ code.Tag =点域(code)     按钮更改标题添加到更新     Me.cmdAdd.Caption =更新     禁用按钮编辑     Me.cmdEdit.Enabled =假 结束与 结束如果 结束小组

这是在code的保存或添加按钮。

 私人小组cmdAdd_Click()
当我们点击按钮添加有两种选择
'1。对于插入
'2。对于更新
如果Me.txt_ code.Tag和放大器; =然后,
    这是为了插入新
    添加数据表
    CurrentDb.ExecuteINSERT INTO KWTable(KW,来源,code)和放大器; _
        VALUES('&放大器; Me.text_key和放大器;,&放大器; Me.combo_source和放大器;,&放大器; _
        Me.txt_ code和; ')

其他
否则(txtID的标签存储学生的ID进行修改)
CurrentDb.ExecuteUPDATE KWTable&放大器; _
SET KW ='&放大器; Me.text_key和放大器; '与& _
,code ='&放大器; Me.txt_ code和; '与& _
源='&放大器; Me.combo_source和放大器; '与& _
WHE​​RE KW ='&放大器; Me.text_key和放大器; '
结束如果
清除表单
cmdClear_Click
在表单列表刷新数据
TableSub.Form.Requery

结束小组
 

解决方案

你只是复制值的字段。他们没有义务对任何子窗体的记录。所以,拯救他们,只是扭转过程:

 随着Me.TableSub.Form.Recordset
    。编辑
    点域(KW)= Me.text_key
    点域(code)= Me.txt_ code
    点域(源)= Me.combo_source
    点域(code)= Me.txt_ code.Tag
    .Update
结束与
 

I have been hammering out the issues of this form for about a week now and have almost come to a solution, but I have hit a brick wall. I have a large form with multiple functions, one of the functions is to edit a subform that houses a list of codes and other various pieces of data. When I click the edit button it auto fills the boxes with the selected data. The function works when I click the update button but when I click the save button it does not actually save the data. The code is:

Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.TableSub.Form.Recordset.EOF And Me.TableSub.Form.Recordset.BOF) Then
'Get data to text box control
With Me.TableSub.Form.Recordset
    Me.text_key = .Fields("KW")
    Me.txt_code = .Fields("Code")
    Me.combo_source = .Fields("Source")
    'Store id of student in tag of text id in case id is modified
    Me.txt_code.Tag = .Fields("Code")
    'Change caption of button add to Update
    Me.cmdAdd.Caption = "Update"
    'disable button edit
    Me.cmdEdit.Enabled = False
End With
End If
End Sub

This is the code for the save or Add button.

Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. For insert
'2. For Update
If Me.txt_code.Tag & "" = "" Then
    'this is for insert new
    'add data to table
    CurrentDb.Execute "INSERT INTO KWTable(KW, Source, Code) " & _
        " VALUES('" & Me.text_key & "','" & Me.combo_source & "','" & _
        Me.txt_code & "')"

Else
'otherwise (Tag of txtID store the id of student to be modified)
CurrentDb.Execute "UPDATE KWTable " & _
" SET KW='" & Me.text_key & "'" & _
", Code='" & Me.txt_code & "'" & _
", Source='" & Me.combo_source & "'" & _
" WHERE KW='" & Me.text_key & "'"
End If
'clear form
cmdClear_Click
'refresh data in list on form
TableSub.Form.Requery

End Sub

解决方案

You're only copying values to the fields. They're not bound to the subform's recordset in any way. So, to save them, just reverse the process:

With Me.TableSub.Form.Recordset
    .Edit
    .Fields("KW") = Me.text_key
    .Fields("Code") = Me.txt_code
    .Fields("Source") = Me.combo_source
    .Fields("Code") = Me.txt_code.Tag
    .Update
End With

这篇关于更新按钮没有完全工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆