- Bitwise conditionals make no sense to the "average" VBA dev. I like that you left a comment here, but consider leaving an remark that the check is done bitwise.
' if sucessfully connected then If (cn.State And adStateOpen) = adStateOpen Then
- I know you asked us not to bash on your use of
cfor collection, and I honestly don't mind it in your customPartscollection class, but I really don't like your use of it here inModule1.
Dim c As Parts Set c = New Parts BuildTheCollection c If Not IsEmpty([A1]) Then Cells.Delete ' clear spreadsheet PrintTheCollection c, 1 ' being called resursively
Have you ever tried doing a Ctl+H to replace a single letter variable name? (Hint: Don't hit "replace all" when doing so.)
PrintTheCollectioncould have a better name, but I'm more concerned that you have to pass it a1here in your Main routine. I would make the argument optional and default to one. It makes it a little cleaner and removes the need for the comment here.Are you sure you're cleaning up as you intend to?
If Not (cn Is Nothing) Then If (cn.State And adStateOpen) = adStateOpen Then cn.Close Set cn = Nothing End If Set cnWrapper = Nothing End If
I would think that you would want to set the connection to Nothing whether or not it was open. Also, calling .Close on an already closed connection does no harm, so I'm not real sure why you're checking it's adState. I feel like this would be simpler.
If Not (cn Is Nothing) Then
cn.Close
Set cn = Nothing
Set cnWrapper = Nothing
End If
This code also seems to show up a lot in what you've shown us here. So, first dry it up by writing a subroutine to take care of the clean up.
Actually, this code shows up a lot in Error Handlers. Would it be simpler to just let the error bubble up and handle the clean up from your
Sub Main? I would consider it. I feel like you've left a lot of places where the global connection could get closed, but then the code just keeps chugging along like it still has a valid connection.What is
p.Tagain??? A part property of some kind or other. ;)
p.T = rs(1)