how do you kill vbe editor thread MsAccess
Hi, all
I'm encountering a weird problem my VBA code opens the vba editor withoout my intention and I want to close it afterwards so user can not click the vba editor open and do "bad" things.
Situation
I have a form with dynamic buttons these buttons are made visible and vba code is added to the form vba module from the database.
The code behind the click buttons depends on the user (or in fact the groups he or she im a member off)
This is the code that creates the problem:
Code:
Private Function PlaceDynamicButtons(GebruikerID As Long, FormulierNaam As String) As Long
Dim DB As DAO.Database
Dim Rs As DAO.Recordset
Dim Frm As Form
Dim Mdl As Module
Dim Ctrl As Control
Dim Btn As CommandButton
Dim BtnName As String
Dim StrSqlSelect As String
Dim StrSqlFrom As String
Dim StrSqlWhere As String
Dim StrSQLOrder As String
'---- Objecten instellen ----------------
DoCmd.OpenForm FormulierNaam, acDesign, , , , acHidden
Set Frm = Forms.Item(FormulierNaam)
Set Mdl = Frm.Module
' ---------------------------------------
StrSqlSelect = "SELECT Distinct TblGebruikerGroep.GebruikerID, TblCommandButtons.DisplayOrder, TblCommandButtons.Naam, TblCommandButtons.Caption, TblCommandButtons.Code, TblCommandButtons.Parent "
StrSqlFrom = "FROM TblGebruikers INNER JOIN (TblGebruikerGroep INNER JOIN (TblCommandButtons INNER JOIN TblControlGroep ON TblCommandButtons.ControleId = " & _
"TblControlGroep.ControleId) ON TblGebruikerGroep.GroepId=TblControlGroep.GroepId) ON TblGebruikers.GebruikerID=TblGebruikerGroep.GebruikerID "
StrSqlWhere = "WHERE TblGebruikerGroep.GebruikerID = " & GebruikerID & " AND TblCommandButtons.Parent = '" & Frm.Name & "' AND TblGebruikers.InDienst <Date() AND ( TblGebruikers.UitDienst >Date() OR TblGebruikers.UitDienst Is Null)"
StrSQLOrder = "ORDER BY TblCommandButtons.DisplayOrder, TblCommandButtons.Naam;"
Set DB = CurrentDb
Set Rs = DB.OpenRecordset(StrSqlSelect & StrSqlFrom & StrSqlWhere & StrSQLOrder, dbOpenDynaset, dbSeeChanges, dbReadOnly)
' verberg alle dynamisch gebruikte knoppen.
For Each Ctrl In Frm.Controls
If TypeOf Ctrl Is CommandButton Then
Set Btn = Ctrl
If InStr(1, Btn.Tag, HIDESTRING) > 0 Then
Btn.Left = 100
Btn.Top = 100
Btn.Width = 200
Btn.Visible = False
End If
End If
Next
Set Btn = Nothing
BtnName = ""
Do While Not Rs.EOF
' voorkom dubbele knoppen
If BtnName <> Rs.Fields("Naam") Then
' ------------------------------------------------------------------------
' Selecteer 1 van de 10 button templates.
' ------------------------------------------------------------------------
BtnName = Rs.Fields("Naam")
Set Btn = Frm.Controls.Item("Btn" & BtnCounter + 1)
BtnName = Rs.Fields("Naam")
Btn.Tag = HIDESTRING
Btn.Width = BUTTON_WIDTH
Btn.Top = FIRST_BUTTON_TOP + (BtnCounter * (BUTTON_HEIGHT + BUTTON_SPACING))
Btn.Height = BUTTON_HEIGHT
Btn.Left = BUTTON_LEFT
Btn.Caption = Rs.Fields("Caption") & ""
' verwijder bestaande click event code
If Mdl.Find(Btn.Name & "_Click", 0, 0, Mdl.CountOfLines, 100) Then
Mdl.DeleteLines Mdl.ProcStartLine(Btn.Name & "_Click", vbext_pk_Proc), Mdl.ProcCountLines(Btn.Name & "_Click", vbext_pk_Proc)
End If
' voeg code voor click event toe
Mdl.CreateEventProc "Click", Btn.Name
Mdl.InsertLines Mdl.ProcBodyLine(Btn.Name & "_Click", vbext_pk_Proc) + 1, "'-- Dynamisch gegenereerde code --" & vbCrLf & Rs.Fields("Code") & vbCrLf & "' ---------------------------------"
Btn.OnClick = "[Gebeurtenisprocedure]"
BtnCounter = BtnCounter + 1
Btn.Visible = True
End If
Rs.MoveNext
Loop
If Not (Btn Is Nothing) Then
PlaceDynamicButtons = Btn.Top + Btn.Height
Else
PlaceDynamicButtons = FIRST_BUTTON_TOP
End If
DoCmd.Close acModule, Mdl.Name
Set Ctrl = Nothing
Set Mdl = Nothing
Set Frm = Nothing
Rs.Close
Set Rs = Nothing
Set DB = Nothing
DoCmd.SetWarnings False
DoCmd.Close acForm, FormulierNaam
DoCmd.SetWarnings True
End Function
I treid to find the process or application, but the weird thing is... the vba editor is listed as a sepparate application, but it's proccess is MSAccess.
I don't wan't to kill MsAccess completly as it's running my application.
How can I kill the vba editor thread but leave MsAccess alive?
thanks in advance?