English 中文(简体)
我如何利用数据库的指挥和结果?
原标题:How can I use the database commands Seek and results NoMatch ?

我的问题是:

我要说的是,我有这些表格:

表1

页: 1“a”

2-“b”

表2

页: 1

2-

3)

现在,用以下代码比较表格的Im:

表2.MoveFirst
Do While Not 表2.EOF
 表1.Seek "=", 表2!field2
  If 表1.NoMatch Then
               go do a lot of things to find that information
  Else 
   表2.Edit
   表2!Field2 = 表1!field2
   表2.update
  End If
 表2.MoveNext
Loop

但线

表2!Field2 = 表1!field2

工作做得不好。 我确信,我在这里做错事,但我有问题找到解决办法。 我甚至不敢肯定我应该做些什么。

EDIT: Field 2 is indexed in table 1, so the seek works.

最佳回答

几个说明。

:

sSQL = "SELECT Field1, FieldX FROM Table2 " _
     & "LEFT JOIN Table1 " _
     & "ON Table2.Field1 = Table1.Field1 " _
     & "WHERE Table1.Field1 Is Null"

页: 1

Dim rs As DAO.Recordset

Set rs = CurrentDB.Openrecordset(sSQL)

  table2.MoveFirst
Do While Not rs.EOF   table2.EOF

  You do not need no match, all these records are missing a match
      table1.Seek "=", table2!field2
      If table1.NoMatch Then
           go do a lot of things to find that information
    rs.MoveNext
Loop
  This can all be done with one update query
      Else 
      table2.Edit
      table2!Field2 = table1!field2
      table2.update
      End If
      table2.MoveNext
      Loop

sSQL = "UPDATE Table2 " _
     & "INNER JOIN Table1 " _
     & "SET table2.Field2 = table1.field2 " 

CurrentDB.Execute sSQL dbFailOnerror

页: 1

问题回答

但<代码>表2! 工作不好

......不能很好地描述什么是错的。

Does the code stop/crash at this line?
Does it run without errors, but do nothing / something else than you expected?

I suppose that you re using DAO Recordsets.
It s hard to give advice without more information, but I ll give it a try:

  1. 页: 1 完全空洞? 你的描述就是这样:

    table2
    1 -
    2 -
    3 -

    如果是,整个住所很可能永远不会被处决。

  2. Can the Recordset table2 be updated?
    Not all types of Recordsets support this, it depends on how you create it. See MSDN: Recordset Object (DAO), there is a list of Recordset types at the beginning.
    If it s not updateable, you should get an error when you call .Update.

如果你重新使用家庭调查记录(按照基督教的建议)的话,你可以改变行踪。

table2!Field2 = table1!field2

纽约总部

table2.Fields("Field2").value = table1.Fields("field2").value

假设两个领域2 的Im是文本数据类型。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签