Skip to main content

Database name is "either invalid or currently in use"

So far my code is pretty simple--it performs a join and extracts duplicates from the resulting database. However, I'm getting the following error when I go to perform the task in my duplicate extraction function:
 
"Invalid database name. The database name provided is either invalid or currently in use."
 
I have used a MsgBox to confirm that the provided database name is a string and that there doesn't seem to be anything wrong with it. My next step in debugging was to go back to the macro recorder version and make one change at a time, checking after each change to see whether the script ran successfully. What broke it was removing the line dbName = "Test Db Name" so that the function was then reliant on the value of dbName passed as an argument. What's strange is that after I broke it and got that error, I put the line back in and it was still broken/I keep getting the error.
 
Does anyone have an idea about what's causing this? My code is below.
 
Option Explicit
 
Dim filePrefix As String
Dim schedFilename As String
Dim glFilename As String
Dim db As database
Dim task As task
Dim field As field
 
Sub Main
 
filePrefix = "Test"
schedFilename = "Test Schedule.IMD"
glFilename = "Test GL Detail.IMD"
 
Call joinSchedGL(schedFilename, glFilename, filePrefix & " Sched Join GL Detail")
Call extractDupes(filePrefix & " Sched Join GL Detail", "COMB_LINE_NO1", filePrefix & " GL Detail Dupes")
End Sub
 
Function joinSchedGL(primDbName As String, secDbName As String, dbName As String)
Set db = Client.OpenDatabase(primDbName)
Set task = db.JoinDatabase
task.FileToJoin secDbName
task.IncludeAllPFields
task.IncludeAllSFields
task.AddMatchKey "DEP_AMT", "CREDIT", "A"
task.AddMatchKey "EXP_AMT", "DEBIT", "A"
task.AddMatchKey "YR_MO", "YR_MO", "A"
task.CreateVirtualDatabase = False
task.PerformTask dbName, "", WI_JOIN_ALL_REC
Set task = Nothing
Set db = Nothing
End Function
 
Function extractDupes(inDbName As String, keyField As String, dbName As String)
Set db = Client.OpenDatabase(inDbName)
Set task = db.DupKeyDetection
task.IncludeAllFields
task.AddKey keyField , "A"
task.Criteria = keyField & ">0"
task.OutputDuplicates = TRUE
task.CreateVirtualDatabase = False
task.PerformTask dbName, ""
Set task = Nothing
Set db = Nothing
End Function
 

rachel.organist Fri, 10/09/2020 - 15:41

Here's another weird observation that may be a clue...
After I run the script and it fails on the duplicate extraction, if I open the database that was successfully created by the join and manually extract the duplicates, the resulting database doesn't appear as a child of the join database; it appears in the root folder/not as a child of anything. I feel like something is going very wrong behind the scenes but I'm not sure what!

Brian Element Sat, 10/10/2020 - 13:49
Hi Rachel, for your first problem when you are sending the file over you are sending omitting the IMD extension, that is why you can't find the file. filePrefix & " Sched Join GL Detail", Should probably be filePrefix & " Sched Join GL Detail.IMD" For your second problem, any chance you can share the files and a screen grab of what is happening?

rachel.organist Mon, 10/12/2020 - 09:44

Oh my gosh I can't believe it was something so simple. D'oh! Thank you, Brian!!

The second issue I thought might be related but it seems to resolve itself after a few moments, or when I click "Refresh List" in the File Explorer pane... so I think it's just a display issue.

The website encountered an unexpected error. Try again later.