问题
I am new to programming.
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.
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.
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 subsequently determined the code would be written in SAX not VBA.
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.
EDIT: 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
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
How do I populate the ListBox with the contents of the Recordset?
回答1:
"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.
来源:https://stackoverflow.com/questions/22050996/how-can-i-create-a-dialog-in-sax-that-lets-a-user-choose-one-item-from-a-records