The code has fixed path information on a lot of places in different SQLs (DoCmd.RunSqL command). I want to replace fixed path info with variable path info. Variable path info is stored in the table.
I managed to achieve that in the following manner:
I replaced path information (\\compName\FolderName\dbname.mdb) with dbName which is the string from table, and it works well.
What I want to do now is to create Module that will save me from writing full code
Dim db As Database
Dim dbName as String
Set db = CurrentDb
Set rs = db.OpenRecordset ("TableName", dbOpendynaset)
rs.FindFirst ("ID = " & 2)
dbName = rs!TableFieldName
rs.Close
db.Close
every time. Something like:
where I would use as variable Function name instead of dbName.
As my idea from the above is not working, could you please help me make module that will enable me to use Function name as variable path information for SQL queries?
Thanks!!!
I managed to achieve that in the following manner:
Code:
Dim db As Database
Dim dbName as String
Set db = CurrentDb
Set rs = db.OpenRecordset ("TableName", dbOpendynaset)
rs.FindFirst ("ID = " & 2)
[B]dbName [/B]= rs!TableFieldName
rs.Close
db.Close
I replaced path information (\\compName\FolderName\dbname.mdb) with dbName which is the string from table, and it works well.
What I want to do now is to create Module that will save me from writing full code
Dim db As Database
Dim dbName as String
Set db = CurrentDb
Set rs = db.OpenRecordset ("TableName", dbOpendynaset)
rs.FindFirst ("ID = " & 2)
dbName = rs!TableFieldName
rs.Close
db.Close
every time. Something like:
Code:
Function VariablePath (dbName as String)
Set db = CurrentDb
Set rs = db.OpenRecordset ("TableName", dbOpendynaset)
rs.FindFirst ("ID = " & 2)
dbName = rs!TableFieldName
rs.Close
db.Close
End Function
where I would use as variable Function name instead of dbName.
As my idea from the above is not working, could you please help me make module that will enable me to use Function name as variable path information for SQL queries?
Thanks!!!