Ok I go that working
Sub VerifyInvoices()
' Declare the QueryTable object
Dim qt As QueryTable
Dim i As Integer
' Set up the connection string, reference an ODBC connection
' There are several ways to do this
' Leave the name and password blank for NT authentication
connstring = "ODBC;DSN=;UID=;PWD=;Database="
sqlstring = "Select uref, hperson, sTotalAMount from Trans (NOLOCK) Where uref in ("
' Set up the SQL Statement
For Each ce In Range("G1:G" & Cells(Rows.Count, 1).End(xlUp).Row)
sqlstring = sqlstring & "'" & ce.Value & "',"
Next ce
sqlstring = Left(sqlstring, Len(sqlstring) - 1) & ")"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Worksheets("Sheet1").Range("A1"), Sql:=sqlstring)
.Refresh
End With
End Sub
I tis returning the resultset to a new sheet starting in A1 and that is great. Now here is the caveat. The actual file may have the same number but a different value in column B and person in column C. How would I add this to the SQL so that it would look like
Select x,y,z from table Where x=A1 and y=B1 and z=C1
Then return that to the sheet correctly.
The whole story is I have a list of invoices from vendors that I want to check against the database to see if I have already entered a similar invoice in the system before uploading a potential duplicate. Again THANKS!!!!!
Bookmarks