A customer is using a CSV file as sort of a database. I need to read the values from the csv file based on customer name. I have sort-of a working model but ran into a snag.
Config file: 2 fields. Search Field (String) and Client List (String List).
The CSV file has entries such as :
"ClientNumber","MatterNumber","ClientName","MatterName" "1","ABC CORP","LEASE DISPUTE" "2","2","AT&T","GENERAL MATTERS" "2","838","AT&T","EEOC-MATERNITY" "2","3657","AT&T","WOODSON" "2","3795","AT&T","JACKSON" "2","4248","AT&T","JOHNSON" "2","4851","AT&T","JONES, NADIA" "2","4997","AT&T","WALL, ANNIE" "2","5353","AT&T","SANDERS" "2","5906","AT&T","THEODORE" "2","5931","AT&T","LABOR"
So in the Search field I enter "AT&T" and it returns multiple entries obviously since there are multiple entries. Even if I select one entry in the list, it selects everything. So it populates the filed as "AT&T;AT&T;AT&T;AT&T;AT&T;"
Here is the script that I am working with:
Const TXTPATH = "C:\Data Files" Const DB = "NewCliMat.csv" Sub Form_OnLoad(Form) Call Form.StatusMsg ("------Running Script-----") Call Form.StatusMsg ("------Clearing Matter List-------") Call Form.UpdateListField("Client List",True,"","") Call Form.SetFieldVisible("Client List",False) End Sub Function Form_OnScan(Form) End Function Sub Field_OnChanged(Form, FieldName, FieldValue) Dim strName : strName = Form.GetFieldValue("Client Search") If (FieldName = "Client Search")Then If(strName = "")Then Call Form.UpdateLabelField("Status", 3, "You must enter a search value") Else Call Form.StatusMsg("Field onChange was called for field name = " & FieldName) Call Form.StatusMsg("Field is set to " & strName) 'This does the search of the client name. 'we will use these values to populate the list box Dim lstClients : lstClients = GetClientInfo(strName) 'no client by that name... If(Len(lstClients) = "")Then Call Form.UpdateLabelField("Status", 3, "No search results found, please try again") Call Form.SetFieldVisible("Client List",False) Else 'show the client list field Call Form.SetFieldVisible("Client List",True) 'populate the list Call Form.UpdateListField("Client List",True,lstClients,"") End If End If End If If (FieldName = "Client List")Then Call Form.StatusMsg("-------------Client List has been changed!!!----------------") End If End Sub Function Field_OnValidate(FieldName, FieldValue) End Function Sub Button_OnClick(Form, ButtonName) End Sub '***************** Custom Section ***************** Const adOpenStatic = 3 Const adLockOptimistic = 3 Const adCmdText = &H0001 Dim strClientName, strMatterNumber Dim lstClientInfo 'this is to store each return value ' Testing msgbox GetClientInfo("AT&T") Function GetClientInfo(strClientName) Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") strPathtoTextFile = TXTPATH objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & strPathtoTextFile & ";" & _ "Extended Properties=""text;HDR=YES;FMT=Delimited""" strFile = DB strClientName = UCASE(strClientName) objRecordset.Open "SELECT * FROM " & strFile & " WHERE ClientName LIKE '%" & strClientName & "%'", objConnection, adOpenStatic, adLockOptimistic, adCmdText Do Until objRecordset.EOF strClientName = objRecordset.Fields.Item("ClientName") strClientNumber = objRecordset.Fields.Item("ClientNumber") strMatterNumber = objRecordset.Fields.Item("MatterNumber") strClientName = Trim(strClientName) strClientNumber = Trim(strClientNumber) strMatterNumber = Trim(strMatterNumber) 'lstClientInfo = lstClientInfo & strClientNumber & ":" & strClientName & ";" & vbCRLF lstClientInfo = lstClientInfo & strMatterNumber & " : " & strClientNumber & ":" & strClientName & ";" objRecordset.MoveNext Loop ' strip the last semi-colon ' This will make the first found entry populate to the top ' Otherwise we get a blank as the first entry lstClientInfo = Left(lstClientInfo,Len(lstClientInfo)-1) RemoveDuplicates(lstClientInfo) GetClientInfo = lstClientInfo End Function
Hope this makes sense. I've been looking at this code all day long! :-\