Question on Variables

That top part is only for declaring variables. Anything else you do inside a Sub or Function.

So things like setting the values of variables, initialising a variable etc has to be done in a Sub or Function.
 
if I did the setting of those variables with the loading of the form would they stay throughout every subroutine of that form?
 
Yep, they will retain their value as long as you have proper error handling in place.
 
hmm just tried it and got Run Time error 91

Object Variable or With Block variable not set

So obviously I dont have proper error handling in place lol

Code:
Private Sub Form_Load()
    Set ctlListBox = Forms!frmCollectorList!FrmListBox       'Point this at ListBox
End Sub
 
LOL never mind Im a moron

I set it for on form load, and forgot to close my form and load it again :) my bad lol

Thanks for the help :)
 
Where's this listbox pointing to?

And remember, I mentioned that you should use Listbox instead of Control to declare the ctlListBox object.
 
it points to 1 field in my tables and ya thats the next part I need to work out how to do what you said with the listbox
 
ok I think I got it all set up right... heres how it looks

Code:
Option Compare Database
Option Explicit

Private ctlListBox As ListBox
Private StrTextName As String
Private StrRecordTblF1 As String
Private StrRecordTbl As String
Private StrRecordTblID As String



Private Sub Form_Load()

    ' Edit the Lines below
    
    Set ctlListBox = Forms!frmPublisherList!publistList     'Point this at ListBox
    StrTextName = "Publisher"                               'Edit this to whatever Name you are editing
    StrRecordTbl = "tblpublishers"                          'Table your editing
    StrRecordTblID = "PublisherID_PK"                       'Table Primary ID Field Name
    StrRecordTblF1 = "PublisherName"                        'Main Table Field your Editing
    
    ' Stop Editing

End Sub


Everything seems to be functional so thats good
 
This is what Im doing if you were curious... the 2 forms that end in list are functional, the other is definitely not yet.

My code probably looks like it was written by an amateur, thats because it has been :)

But Im learning as I go and thats whats important
 

Attachments

Users who are viewing this thread

Back
Top Bottom