VBA Newbie - inherited Access DB - Blank code (1 Viewer)

tommu319

New member
Local time
Today, 03:28
Joined
Jan 26, 2022
Messages
16
I am quite new to VBA and have just inherited an Access DB that has quite a bit of VBA included.

As I look at the code I see several lines that appear to have no content - such as:

Private Sub DeleteCurrentContact_Click()

End Sub

And

Private Sub PCN_Click()

End Sub

I'd like to just delete those, as I "think" they have no function, but as a newbie I am just a bit concerned.

Can I delete them, safely??

TIA
 

GinaWhipp

AWF VIP
Local time
Today, 03:28
Joined
Jun 21, 2011
Messages
5,899
Sometimes people forgot to delete old useless lines. So, with that in mind, make a copy and then delete away.

Also, you can *spot* unused sections of code. If you click in between Private Sub and End Sub and at the top on the right you see something like

Private Sub DeleteCurrentContact_Click

Then is most likely useless code. You should see Click.
 

tommu319

New member
Local time
Today, 03:28
Joined
Jan 26, 2022
Messages
16
Sometimes people forgot to delete old useless lines. So, with that in mind, make a copy and then delete away.

Also, you can *spot* unused sections of code. If you click in between Private Sub and End Sub and at the top on the right you see something like

Private Sub DeleteCurrentContact_Click

Then is most likely useless code. You should see Click.
Thank you. I did as you suggested, including making a copy of the code before deleting, and then went about it.…

All seems fine and the database seems to open as normal. I was sure it was ok to delete it.. but confirmation from you gave me the nerve to do it.. LOL

Thanks again.
 

oleronesoftwares

Passionate Learner
Local time
Today, 00:28
Joined
Sep 22, 2014
Messages
1,159
I'd like to just delete those, as I "think" they have no function, but as a newbie I am just a bit concerned.

Can I delete them, safely??
After deleting in VBA, also go to the PCN on click properties and remove any reference if it still exists of the code.
 

Minty

AWF VIP
Local time
Today, 08:28
Joined
Jul 26, 2013
Messages
10,371
After deleting in VBA, also go to the PCN on click properties and remove any reference if it still exists of the code.
There won't be a reference, at least on newer versions of access, if the code is removed and you do a C&R.
A compact and repair should remove any totally empty code modules. It won't if there are comments still present.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:28
Joined
Oct 29, 2018
Messages
21,493
Just FYI, I could be wrong, and it may not even apply to the OP's particular situation, but I think empty subs are required when you use classes and sink events (With Events). No?
 

oleronesoftwares

Passionate Learner
Local time
Today, 00:28
Joined
Sep 22, 2014
Messages
1,159
There won't be a reference, at least on newer versions of access, if the code is removed and you do a C&R.
A compact and repair should remove any totally empty code modules. It won't if there are comments still present.
Well said
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:28
Joined
May 21, 2018
Messages
8,554
Just FYI, I could be wrong, and it may not even apply to the OP's particular situation, but I think empty subs are required when you use classes and sink events (With Events). No
The sub stubs are not required, but the event property must be set to "Event Procedures". Or the event will not be raised.
So if you are trapping the deletecurrentcontact click event, you either need to add "[event procedure]" manually or you can do it in code from the class that traps the event.
DeleteCurrentContact

For example this class traps a lot of event from different objects. In the class module I make sure to add the event handler property
Code:
Public Sub InitalizeFilterCombo(TheComboBox As Access.ComboBox, Optional FilterFieldName As String = "All_Fields", _
                      Optional TheSearchType As SearchType = SearchType.anywhereinstring, _
                      Optional HandleArrows As Boolean = True, _
                      Optional HandleInternationalCharacters As Boolean = True)
  
   On Error GoTo errLabel
   Dim rs As DAO.Recordset
   If Not TheComboBox.RowSourceType = "Table/Query" Then
      MsgBox "This class will only work with a combobox that uses a Table or Query as the Rowsource"
      Exit Sub
   End If
   Set mCombo = TheComboBox
   Set mForm = TheComboBox.Parent
   mHandleArrows = HandleArrows
   mAutoCompleteEnabled = True
   mHandleInternationalCharacters = HandleInternationalCharacters
   'HandleArrows allows you to use the arrow keys to move up and down without selecting the value
   mCombo.OnClick = "[Event Procedure]"
   If mHandleArrows = True Then
      mCombo.OnKeyDown = "[Event Procedure]"
      mCombo.OnClick = "[Event Procedure]"
   End If
   mFilterFieldName = FilterFieldName
   mSearchType = TheSearchType
 
   mForm.OnCurrent = "[Event Procedure]"
   mForm.OnClose = "[Event Procedure]"
   mCombo.OnGotFocus = "[Event Procedure]"
   mCombo.OnChange = "[Event Procedure]"
   mCombo.OnClick = "[Event Procedure]"
   mCombo.AfterUpdate = "[Event Procedure]"
   mForm.OnClose = "[Event Procedure]"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:28
Joined
Oct 29, 2018
Messages
21,493
The sub stubs are not required, but the event property must be set to "Event Procedures". Or the event will not be raised.
So if you are trapping the deletecurrentcontact click event, you either need to add "[event procedure]" manually or you can do it in code from the class that traps the event.
DeleteCurrentContact

For example this class traps a lot of event from different objects. In the class module I make sure to add the event handler property
Code:
Public Sub InitalizeFilterCombo(TheComboBox As Access.ComboBox, Optional FilterFieldName As String = "All_Fields", _
                      Optional TheSearchType As SearchType = SearchType.anywhereinstring, _
                      Optional HandleArrows As Boolean = True, _
                      Optional HandleInternationalCharacters As Boolean = True)
  
   On Error GoTo errLabel
   Dim rs As DAO.Recordset
   If Not TheComboBox.RowSourceType = "Table/Query" Then
      MsgBox "This class will only work with a combobox that uses a Table or Query as the Rowsource"
      Exit Sub
   End If
   Set mCombo = TheComboBox
   Set mForm = TheComboBox.Parent
   mHandleArrows = HandleArrows
   mAutoCompleteEnabled = True
   mHandleInternationalCharacters = HandleInternationalCharacters
   'HandleArrows allows you to use the arrow keys to move up and down without selecting the value
   mCombo.OnClick = "[Event Procedure]"
   If mHandleArrows = True Then
      mCombo.OnKeyDown = "[Event Procedure]"
      mCombo.OnClick = "[Event Procedure]"
   End If
   mFilterFieldName = FilterFieldName
   mSearchType = TheSearchType
 
   mForm.OnCurrent = "[Event Procedure]"
   mForm.OnClose = "[Event Procedure]"
   mCombo.OnGotFocus = "[Event Procedure]"
   mCombo.OnChange = "[Event Procedure]"
   mCombo.OnClick = "[Event Procedure]"
   mCombo.AfterUpdate = "[Event Procedure]"
   mForm.OnClose = "[Event Procedure]"
Ah, got it. Thanks!
 

Users who are viewing this thread

Top Bottom