Delete remote module (1 Viewer)

jukos

New member
Local time
Today, 08:04
Joined
Dec 15, 2017
Messages
9
Deleting a module in remote database using vba is working using this code :

Code:
Dim objAcc As Access.Application
Set objAcc = GetObject("\\grh503\Electronics\database_programs\z_rest_of_em\tools\golive\GoLive.accdb")
objAcc.DoCmd.DeleteObject acModule, "tools-for_all_db_123"
objAcc.Application.Quit
Set objAcc = Nothing

BUT... I wont know what last 3 characters will be in the module name "tools-for_all_db_123" . I would like to delete the module starting with "tools-for_all_db"

Thanks all!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:04
Joined
Oct 29, 2018
Messages
21,474
Just off the top of my head, maybe you could use the MSysObjects table to get those names?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:04
Joined
Feb 28, 2001
Messages
27,191
You can enumerate the AllModules collection in a loop to do something like

Code:
For n = 0 to objAcc.AllModules.Count - 1
   xxx = objAcc.AllModules(n).Name
   if Left(xxx, 15 ) = "tools-for_all_db_" then ...
   ...
Next n

in a loop to find the module where the first part of the name matches your goal. This works because that is one of the ways iterate through collections. When you use AllModules it actually defaults to the current DB, but with a prefix to qualify which DB you meant, it should work.
 

jukos

New member
Local time
Today, 08:04
Joined
Dec 15, 2017
Messages
9
I tried this code to test but getting compile error:
Annotation 2023-06-30 103448.jpg
 

Josef P.

Well-known member
Local time
Today, 17:04
Joined
Feb 2, 2023
Messages
827
objAcc.CurrentProject.AllModules

Tip: If you want to delete multiple times within the loop, I would run the loop backwards.
 

isladogs

MVP / VIP
Local time
Today, 16:04
Joined
Jan 14, 2017
Messages
18,236
To get a list of modules....

Code:
Sub ListModulesInExtDb()
    Dim strFilePath As String, obj As Object
    Dim objAcc As Access.Application
    
    strFilePath = "Full file path here"
    Set objAcc = GetObject(strFilePath)
    
    For Each obj In objAcc.CurrentProject.AllModules
        Debug.Print obj.Name
    Next
    
    Set objAcc = Nothing
End Sub

Definitely follow Josef's advice if you need to do multiple deletes or results may not be what you expect
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:04
Joined
Feb 28, 2001
Messages
27,191
Whoops... it has been so long that I did that, I forgot the "CurrentProject" component. My bad.
 

Users who are viewing this thread

Top Bottom