Alexandroid
New Member
- Joined
- Jan 29, 2014
- Messages
- 16
Hey everyone and thanks for all your help in the past!
I'm trying to search for a value in a closed workbook and if that value is found, I would know that that unique ID has already been used and move onto the next number. I'm choosing to use the ADODB method instead of having it open in the background and not be visible. I'm hoping that by using ADODB I can make the process much faster.
I'm having issues when I run the Recordset.find method and receive the error:
Run-time error '3265':
Item cannot be found in the collection corresponding to the requested name or ordinal.
The closed workbook is being used as a database that is storing series of numbers that have been used before when we are trying to assign unique IDs to some documents. Before I came here, They would just randomly generate numbers which lead to them being all over the place and now they receive errors that they have duplicate IDs. I've added all the ID's in the closed Spreadsheet (Database.xlsx), and I'm trying to search through it with a macro that can be run on many different workstations but that would all point to the Database that is on a network drive.
In the Database spreadsheet, I've named the area with all the numbers "TableName" just to make it simple. Each column of the database has numbers that start with a section number (Column A would be 1230001,1230002, 1230003 and Column B would be 456009, 456010, 456025... The numbers are not sequential either.) and the header row would contain the specific section (123 or 456 in this example).
I was unable to attach example files but that would make it much easier to understand I believe. If you think you can assist me with this and would like the files, please let me know and I will send them to you.
Thank you!
Alex
I'm trying to search for a value in a closed workbook and if that value is found, I would know that that unique ID has already been used and move onto the next number. I'm choosing to use the ADODB method instead of having it open in the background and not be visible. I'm hoping that by using ADODB I can make the process much faster.
I'm having issues when I run the Recordset.find method and receive the error:
Run-time error '3265':
Item cannot be found in the collection corresponding to the requested name or ordinal.
The closed workbook is being used as a database that is storing series of numbers that have been used before when we are trying to assign unique IDs to some documents. Before I came here, They would just randomly generate numbers which lead to them being all over the place and now they receive errors that they have duplicate IDs. I've added all the ID's in the closed Spreadsheet (Database.xlsx), and I'm trying to search through it with a macro that can be run on many different workstations but that would all point to the Database that is on a network drive.
Code:
Sub QueryDB()
Dim strMyPath As String, strDBName As String, strDB As String
Dim adoRecSet As ADODB.Recordset
Dim i As Long
strDBName = "Database.xlsx"
strMyPath = ThisWorkbook.Path
strDB = strMyPath & "\" & strDBName
Dim connDB As New ADODB.Connection
connDB.Open ConnectionString:="Provider = Microsoft.ACE.OLEDB.12.0; Data Source=" & strDB & "; Extended Properties='Excel 12.0;HDR = YES'; Mode =" & adModeShareDenyNone
Set adoRecSet = New ADODB.Recordset
Dim strTable As String
strTable = "TableName"
adoRecSet.Open Source:=strTable, ActiveConnection:=connDB, CursorType:=adOpenKeyset, LockType:=adLockOptimistic
adoRecSet.Find "TableName = '456010'"
adoRecSet.Close
connDB.Close
Set adoRecSet = Nothing
Set connDB = Nothing
End Sub
In the Database spreadsheet, I've named the area with all the numbers "TableName" just to make it simple. Each column of the database has numbers that start with a section number (Column A would be 1230001,1230002, 1230003 and Column B would be 456009, 456010, 456025... The numbers are not sequential either.) and the header row would contain the specific section (123 or 456 in this example).
I was unable to attach example files but that would make it much easier to understand I believe. If you think you can assist me with this and would like the files, please let me know and I will send them to you.
Thank you!
Alex
Last edited: