PDA

View Full Version : Rename Query



richardSmith
07-28-2014, 11:19 AM
I am importing queries from a master database into other databases. Well now there is one additional caveat the queries may already exist in the destination database. In vba how can you if query already exists append BAD to the end of the name of the query then import the query from the master database?

richardSmith
07-28-2014, 12:45 PM
This is close...can someone help me tweak it to perfection?


Dim qName(0 to 2) As String
Dim position As Long
Dim strOld As String
Dim strNew As String
Dim aob As AccessObject
Dim obj As Object

qName(0) = "killerelf"
qName(1) = "ice"
qName(2) = "fire"

For position = LBound(qName) to UBound(qName)
Set obj = CurrentData.AllQueries
For Each aob In obj
strNewObj = Replace(aob.Name, position, position & "_bad")
If aob.Name == program Then
DoCmd.Rename strNewObj, acQuery, aob.Name
End If
Next aob
Next position