如何在 SAX 中创建允许用户从记录集中选择一项的对话框? [英] How can I create a dialog in SAX that lets a user choose one item from a recordset?

查看:43
本文介绍了如何在 SAX 中创建允许用户从记录集中选择一项的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.

我正在尝试在一个名为 Captovation Capture 的程序中编写一个.基本上这个程序是用于扫描文档(通常是某种形式的),然后索引它们(通过在字段中输入元数据).

I'm trying to write a macro in a program called Captovation Capture. Basically this program is for scanning documents (usually forms of some kind), and then indexing them (by typing in metadata into fields).

我们目前使用一些(由其他人编写),它们会根据在另一个字段中输入的数据自动填充某些字段.

We currently use some macros (that were written by someone else) that will automatically fill some of the fields based on data entered in another field.

例如,您可以在EMPLOYEE NUMBER字段中输入一个员工的(唯一的)编号,宏将使用该编号查询我们的数据库,然后自动填写该员工的第一个和最后一个姓名、部门等

For example, you can enter in an employee's (unique) number into the EMPLOYEE NUMBER field, and the macro will query our database using the number, and then automatically fill in the employee's first and last name, department, etc.

我正在编写这样一个,它可以返回多个结果,我需要让用户看到可能匹配的列表,然后选择正确的一个.

I'm writing a macro like this that could return multiple results, and I need to allow the user to see the list of possible matches and then choose the correct one.

我所知道的关于的全部内容是帮助文件中的内容:Captovation Capture 支持与 Visual Basic for Applications (VBA) 兼容的编程语言,用于编写和调试宏."

All I know about the macros is what's in the help file: "Captovation Capture supports a Visual Basic for Applications (VBA) compatible programming language for writing and debugging macros."

Edit 20150315:OP 随后确定代码将使用 SAX 而不是 VBA 编写.

Edit 20150315: OP subsequently determined the code would be written in SAX not VBA.

所以在这一点上,我能够查询数据库并获得一个填充了结果的 ADODB.Recordset 对象,我只是不知道如何向用户显示这些结果,并且让他们选择一个.

So at this point, I am able to query the database and get a ADODB.Recordset object populated with the results, I just don't know how to display those results to the user, and let them choose one.

这是我到目前为止的代码片段.

Here is a snippet of the code I have so far.

If (Len(FieldValue) > 0 And InStr(1, "VendorName", FieldName)) Then
  Dim conn As New ADODB.Connection
  Dim cmd As New ADODB.Command
  Dim rst As New ADODB.Recordset
  Dim ConnectStr As String

  ConnectStr = "XXXXXXXXX"

  conn.Open (ConnectStr)
  cmd.CommandType = adCmdText

  cmd.CommandText = "select XXXX from XXX where XXX like '" & FieldValue & "' and XXX = 'C' and XXX IS NULL"
cmd.ActiveConnection = conn

'MsgBox cmd.CommandText

Set rst = cmd.Execute()

If rst Is Nothing Then
  Exit Sub
End If

If rst.Fields(0) = 0 Then
  MsgBox("VendorGID Not Found, Please check the Vendor Name")
  mctlIndex.SetFieldValue "VendorGID", ""
  Exit Sub
End If

'At this point, this code assumes that there is exactly 1 result from the query
'but I need some code here to present all the results and let the user choose one.

mctlIndex.SetFieldValue "VendorGID", rst.Fields(0).Value
rst.Close

添加一个UserDialog后,生成了这段代码:

After adding a UserDialog, this code was generated:

Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1
      ListBox 30,21,350,35,ListArray(),.ListBox1
End Dialog
Dim dlg As UserDialog
Dialog dlg

如何用 Recordset 的内容填充 ListBox?

How do I populate the ListBox with the contents of the Recordset?

推荐答案

"所以事实证明我正在使用名为Sax Basic"的 VBA 实现.一旦我发现了如何访问帮助文件(奇怪的是,帮助文件无法通过任何按钮或菜单获得,我必须按 F1 键才能将其拉起)我能够通过这个混乱我的方式.基本上,填充 ListBox 的唯一方法是在您创建它时;您将它指向一个字符串数组,这就是它用来填充列表的内容.所以我的粗略解决方案是通过记录集保持MoveNext",直到我点击EOF"并将每个结果保存到一个数组中,然后使用它创建列表框."– user3357334

"So it turns out that I'm using an implementation of VBA called "Sax Basic." Once I found out how to access the help files (strangely, the help file was not available via any button or menu, I had to press the F1 key to pull it up) I was able to muddle my way through this. Basically, the ONLY way to populate the ListBox is when you create it; you point it to a array of strings, and that's what it uses to populate the list. So my crude solution was to keep "MoveNext"ing through the recordset until I hit "EOF" and saving each result into an array, and then using that to create the ListBox." – user3357334

社区维基.答案在评论中.在搜索中找到此主题的任何人都会看到答案,并且更有可能寻找有用的答案.

Community wiki. Answer is in a comment. Anyone finding this topic in a search will see there is an answer and is more likely to look in for a hopefully useful answer.

这篇关于如何在 SAX 中创建允许用户从记录集中选择一项的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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