使用.Edit& 。在RecordSet上更新 [英] Using .Edit & .Update on a RecordSet

查看:67
本文介绍了使用.Edit& 。在RecordSet上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表(Table1),我希望我的用户能够控制优先级。对于这个问题,只考虑2个字段,Priority(作为整数)和Desc(作为String)。


我的表单(Form1,Continuous)显示绑定的文本框,txtPriority和txtDesc。用户更改txtPriority中的值,然后按cmdReOrder。这应该将Priority(在表1中)从1重新编号为n,并以新的顺序显示记录。


以下代码完美运行,如果调用两次。换句话说,如果声明Call ReOrder,则表示Call ReOrder。是两行相同的代码,这是我想要的。我在这里找不到什么小东西?

I have a table (Table1) and I want my users to be able to control the priority. For this question, consider only 2 fields, Priority (as Integer) and Desc (as String).

My form (Form1, Continuous) displays bound textboxes, txtPriority and txtDesc. The user changes the values in txtPriority, and then presses cmdReOrder. This should renumber Priority (in Table1) from 1 to n, and display the records in the new order.

The below code works perfectly, IF CALLED TWICE. In other words, if the statement "Call ReOrder" is 2 identical lines of code, this works as I intended. What little item am I missing here?

展开 | 选择 | Wrap | 行号

推荐答案


我有一个表(Table1),我希望我的用户能够控制优先级。对于这个问题,只考虑2个字段,Priority(作为整数)和Desc(作为String)。


我的表单(Form1,Continuous)显示绑定的文本框,txtPriority和txtDesc。用户更改txtPriority中的值,然后按cmdReOrder。这应该将Priority(在表1中)从1重新编号为n,并以新的顺序显示记录。


以下代码完美运行,如果调用两次。换句话说,如果声明Call ReOrder,则表示Call ReOrder。是两行相同的代码,这是我想要的。我在这里找不到什么小东西?

I have a table (Table1) and I want my users to be able to control the priority. For this question, consider only 2 fields, Priority (as Integer) and Desc (as String).

My form (Form1, Continuous) displays bound textboxes, txtPriority and txtDesc. The user changes the values in txtPriority, and then presses cmdReOrder. This should renumber Priority (in Table1) from 1 to n, and display the records in the new order.

The below code works perfectly, IF CALLED TWICE. In other words, if the statement "Call ReOrder" is 2 identical lines of code, this works as I intended. What little item am I missing here?

展开 | 选择 | Wrap | 行号


除非我遗漏了什么,否则我唯一的区别就是在我的代码和解决方案代码之间找到Me.Requery的最后一行的变化。 to Me.RecordSource =" Select * From Table1 Order By [Priority]"并且在模块顶部包含Dim dbs As DAO.Database,rst As DAO.Recordset,因为它们在别处使用,并且在将代码转换为a时省略(遗憾)错误测试用例。


另外,显示的代码缺少一个空白(FROM子句),因此不起作用。在演示文稿中也出错,因为它显然无法正常显示。


我总是尝试删除问题所不需要的所有代码。我不想让别人去弄清楚我在做什么,只看看问题。


结果没有变化。从Me.ReQuery更改为Me.RecordSource。 。 "给出了同样的问题,而且实际的表格是基于一个更复杂的查询,我会把它留给我。


我有两个有效的解决方案。 1)两次调用ReOrder,或2)通过Set dbs = CurrentDb中的代码循环。通过Me.ReQuery两次。两者都有效,但我不明白他们为什么要这样做,为什么一旦通过就不行。


OldBirdman

P.S.将离开这台计算机,直到下周三(加利福尼亚时间= +8)。
Unless I am missing something, the only differences I can find between my code and the solution code is the change of the last line from "Me.Requery" to Me.RecordSource = "Select * From Table1 Order By [Priority]" and the inclusion of "Dim dbs As DAO.Database, rst As DAO.Recordset", which I had, at the top of the Module, as they are used elsewhere, and omitted (unfortunately) in error when converting the code to a test case.

Also, the code as presented is missing a blank (FROM Clause), and therefore would not work. Error also in presentation, as it obviously could not work as shown.

I always try to remove all code not necessary to the problem. I don''t want someone to have to work to figure out what I''m doing, just look at the problem.

The results are unchanged. Changing from Me.ReQuery to Me.RecordSource ". . ." gives same problem, and as actual form is based on a more complex query, I will leave it my way.

I have 2 solutions that do work. 1) Call ReOrder twice, or 2) Loop thru the code from the "Set dbs = CurrentDb" thru "Me.ReQuery" twice. Both work, but I don''t understand why they should, and why once thru doesn''t.

OldBirdman
P.S. Will be away from this computer until next Wednesday (California time=+8).


经过大量测试(使用Debug.Print),不起作用的语句是rst.Update ;。 rst!Priority = i已完成,但记录未更新。


我创建了一个新的子程序PriorityReorder为了隔离测试代码。


如果我调用SubPriorityReorder两次,它会工作。我已经停止了End Sub的代码。声明并拖了???我没有这个语言?我将执行箭头的语句拖回到set dbl =。 。 。声明和运行,它的工作原理。


我搬了???什么是暗淡的通用术语。声明?宣布?再说一遍,我的问题很难对付???我已经将dbs和Drst的Dim语句移动到了Sub中。没有帮助。


我把sub的所有语句放在一个循环中(对于j = 1到2 ...下一个j)。当然,除了昏暗的陈述。这应该与手动移动活动语句相同。这不起作用。


这个Sub工作的唯一方法是调用它两次。在我的程序中,它实际上是cmdPriority _Click调用的子程序。所以现在
After much testing (with Debug.Print), the statement that does not work is "rst.Update". "rst!Priority = i" is done, but the record is not updated.

I have created a new subroutine "PriorityReorder" in order to isolate the code for testing.

If I call the Sub "PriorityReorder" twice, it will work. I have stopped the code at the "End Sub" statement and dragged the ??? I don''t have the language for this ?? I drag the statement executing arrow back to the set dbl = . . . statement and run, and it works.

I have moved the ??? What is the generic term for "Dim" statements? Declare? again, I have trouble phrasing my questions ??? I have moved the Dim statements for dbs and rst into the Sub. No help.

I put all the statements of the sub in a loop (for j=1 to 2 . . . next j). Except for the Dim statements, of course. This should be the same as manually moving the active statement. This does not work.

The only way this Sub will work is to call it twice. In my program, it is actually a subroutine called by cmdPriority _Click. So now
展开 | 选择 | Wrap | 行号


这篇关于使用.Edit& 。在RecordSet上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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