Sub DeleteAccessTable()
Dim dbConnection As ADODB.Connection
Dim dbCommand As ADODB.Command
Dim dbFileName As String
dbFileName = "C:\YourFilePath\Database1.accdb"
Set dbConnection = New ADODB.Connection
With dbConnection
.Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFileName & _
";Persist Security Info=False;"
.Open dbFileName
End With
Set dbCommand = New ADODB.Command
Set dbCommand.ActiveConnection = dbConnection
dbCommand.CommandText = "DROP TABLE TableTest"
dbCommand.Execute
Set dbCommand = Nothing
Set dbConnection = Nothing
End Sub
Sub DeleteAccessTable()
Dim dbConnection As ADODB.Connection
Dim dbCommand As ADODB.Command
Dim dbFileName As String
Dim StrUser As String
StrUser = Environ("Username")
dbFileName = "C:\YourFilePath\Database1.accdb"
Set dbConnection = New ADODB.Connection
With dbConnection
.Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFileName & _
";Persist Security Info=False;"
.Open dbFileName
End With
Set dbCommand = New ADODB.Command
Set dbCommand.ActiveConnection = dbConnection
dbCommand.CommandText = "DROP TABLE" & StrUser
dbCommand.Execute
Set dbCommand = Nothing
Set dbConnection = Nothing
Debug.Print StrUser
End Sub
I guess I'm not following you in the sense that I don't understand what good that information does in the macro. If you want to know the username, could you not just have a message box at the end of the macro that says the table has been deleted by the username, example:
MsgBox "The table has been deleted by " & Environ("Username")
Keep in mind, environ(username) deals with the network user name, wheeras the name displayed in the Options dialog is derived by Application.Username.
Sorry to be redundant with this final comment, but I don't understand what you are after, seeing as the person who deletes the table, that is, the person who executes the macro, knows who they are.