|
Question : CHECK FOR EXISTENCE:lookup string in external db
|
|
Hi,
I need to do the following: scan dir *check filenames have good filenames appear in a listbox *have bad filenames passed to a textbox [be able to continue:still use the recordset of listbox.selected after user selects from (good) files in listbox.]
I have the rest of the functionality done, but the *check filenames and pass to textbox. I know how to do this within pure vb, and within sql, but not in this scenario: a directory includes files, files are scanned using dir batch, *filenames must be checked against an external databse in an exists/not exists style, listbox populates from dir batch with filenames that match (exist) and filenames that don't match (not exists) are listed in a textbox. a filename that doesn't exist should not halt the dir batch or the app, just list in the textbox.
Current Code with pseudocode where necessary:
Sub ListFiles_Enter()
On Error GoTo ErrorHandler
Dim strFileName As String Dim strFileList As String Dim strEmployee As String Dim strManager As String Dim strSales As String strFileName = Dir("C:\*.csv") 'check filename * compare strEmployee with Employee table in C:\masterdb.mdb * compare strManager with Manager table in C:\masterdb.mdb *compare strSales with SalesType table in C:\masterdb.mdb
* 'Else 'if filename doesn't match, print out to a textbox on another form ' End If Do Until strFileName = "" strFileList = strFileList & strFileName & ";" strFileName = Dir Loop ListFiles.RowSource = strFileList End Sub
sample files:
Genovi_Smith_new.xls Gilbert_Davidson_maint.xls Gilbert_Davison_upgrade.xls (where Davison is not a manager name, sp.)
tia!
|
|
Answer : CHECK FOR EXISTENCE:lookup string in external db
|
|
Take a look at this. requires all three to be a match
' Check for Valid Name in tables, add to "Good" list ' Check Employee table varEli = DLookup("[EAccount]", "tbl_ELAccount", "[EAccount]='" & strEmployee & "'") ' Check Manager table varManger = DLookup("[MAccount]", "tbl_MLAccount", "[MAccount]='" & strEmployee & "'") ' Check Sales Table varSalesType = DLookup("[SalesType]", "tbl_Sales", "[SalesType]='" & strType & "'") If "" & varEli <> "" And "" & varManger <> "" And "" & varSalesType <> "" Then ' Got one !GoodFile = True ' Change the 'No' To 'Yes' End If ' Add data to the table !LastName = strEmployee !FirstName = strFirstName !SalesType = strType !FileName = strFileName .Update ' Save the record strFileName = Dir ' Get next entry.
|
|
|
|