Reputation: 120
I have the following code:
Dim location As String
location = DLookup("[db_location]", "locationandsetup")
DBEngine.CompactDatabase "'" & location & "'\ReadinessDatabase_Backend.accdb", "'" & location & "'\ReadinessDatabase_Backup.accdb"
When I put it into action it says "not a valid file name". The file name is correct and the variable "location" shows the right location, so I can't figure out why it's saying it's not a valid file name. Any ideas?
The reason behind using the variable is because the user, when they run first time setup, selects where the database is and then that is stored into a table. Then anytime they need the location to perform any actions within the database it will use the location stored in the table. I've used this method on numerous subs and it works with no issues, just in this one action it won't work.
Edit: db_location is the path Locationandsetup is the table
When I copy and paste the path from the table into VBA, replacing the variable, it works.
Upvotes: 0
Views: 75
Reputation: 55806
Strip the quotes:
DBEngine.CompactDatabase location & "\ReadinessDatabase_Backend.accdb", location & "\ReadinessDatabase_Backup.accdb"
Upvotes: 1