且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在表格中删除行后刷新表格(在VB中)

更新时间:2023-12-04 12:49:04


您好,


我有问题....我有一个基于表的表单,其中包含几个控件(文本和组合框)。在表单中有一个命令按钮,可以删除控件中的某些数据。如果有人通过记录选择器,某些控件可能会显示#deleted。这是个问题。如果我关闭表单并重新打开,问题就会消失。


我怎样才能立即刷新表格,这样就不会发生?我的每个控件都有一个'on_click''事件,因此已经使用过。谢谢,我是一个新手,需要一些帮助!
Hello,

I''ve got a problem....I have a form based on a table with contains several controls (text and combo boxes). In the form there is a command button where some data in the controls can be deleted. If someone goes through the record selector, some of the controls may show #deleted. This is a problem. If I close the form and reopen, the issue goes away.

How can I immediately refresh the table so this doesn''t occur? Each of my controls has an ''on_click'' event, so those are already used. Thanks, I"m a newbie and need some help!



在执行delete record命令后的下一行代码中,放置以下代码:

Me.Refresh

On the next line of code after you execute the delete record command, place the following code:
Me.Refresh



在执行delete record命令后的下一行代码中,放置以下代码:

Me.Refresh
On the next line of code after you execute the delete record command, place the following code:
Me.Refresh



你好puppydogbuddy,


我做了你所说的(见代码)

Private Sub cmdErasePic_Click ()

如果不是IsNull([imageFile])那么

如果MsgBox(这个图像将被永久删除,你确定吗?,vbYesNo + vbQuestion) = vbYes然后

我!frmimagesubform.Form![imgPicture] .Picture =""

Me![imageFile] = Null

SysCmd acSysCmdClearStatus

DoCmd.SetWarnings False

Dim mysql As String''通过将SQL字符串赋值给变量mysql来声明变量

mysql =&quot ; DELETE * FROM imageIn ventory其中imageInventory.imageID =" &安培;我![imageID]

Me.Refresh

''下一步执行SQL语句

DoCmd.RunSQL mysql

DoCmd.SetWarnings True

致电表格_当前

结束如果

结束如果

结束次级


会发生什么,包含数据的每个控件,更改为#Deleted然后,如果我单击下一个选项卡转到另一个记录,我会收到一条消息类型不匹配... ..我必须点击下一个(& previous)再次开始使用记录选择器......


删除后似乎没有立即刷新。救命。我甚至试过requery,但仍然在列表中留下''删除''记录为#Deleted

Hello puppydogbuddy,

I did what you said (see code)
Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim mysql As String ''Declare the Variable by assigning SQL String to the variable mysql
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
Me.Refresh
''Execute the SQL Statement is next
DoCmd.RunSQL mysql
DoCmd.SetWarnings True
Call Form_Current
End If
End If
End Sub

What happens is immediately each of the control that contained data, changes to #Deleted and then, if I click the next tab to go to another record, I get a message "Type Mismatch"....I have to click next (& previous) to begin using the record selector again......

It doesn''t seem to immediately refresh after delete. Help. I even tried requery, but that still leaves that ''deleted'' record in the list as #Deleted


将Do.Remresh放在DoCmd.RunSql之后。您在执行删除之前已经拥有它。
Place the Me.Refresh after the DoCmd.RunSql. You currently have it before the delete is executed.