Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer 15 Lessons    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Lesson 1 Dev15
Abraham Breuer 
     
5 years ago
Passing a Control as a Parameter is explained very quickly and I can't understand it even I listened to it many times do you cover this method in future lessons?
thank you
Adam Schwanz  @Reply  
           
5 years ago
Passing a control is awesome. Its used in a lot of the more advanced stuff. A big advantage of it is you don't have to rewrite long code 50 times if you have a lot of buttons using it. What dont you understand? Do you have any questions about it?

What your doing in the button is saying i want to run the function and then i want it to replace the value with what im sending it wherever its at.

ChangeCustomerStatus is saying i want to use the function and then im sending ActiveCustomerList for the C value. Now if you go up to the function with all the code. Anywhere it says C it will now act as if C says ActiveCustomerList.
Abraham Breuer OP  @Reply  
     
5 years ago
Thanks, adam
can you explain what means ' I'm sending ActiveCustomerList for the c value '
Adam Schwanz  @Reply  
           
5 years ago
Sure, I'll try to use it in the simplest example I can think of. Assume I'm using it just to do a calculation on a field called Total.

Private Sub AddNumbers (C As Integer)
Total = 1 + C
End Sub

Now my button has the code
AddNumbers 4

That 4 is being sent to the AddNumbers sub/function and is going to replace the C value. So my function will act like this:
Total = 1 + 4

Now if I had a button with AddNumbers 3 then C is being replaced by 3. It will act like this:
Total = 1 + 3

Does this help at all?
Adam Schwanz  @Reply  
           
5 years ago
This makes it so I don't have to write out
Total = 1 + 3 for one button
Total = 1 + 4 for another button maybe 50 buttons later I've wrote 10 pages of code to get to
Total = 1 + 55

Insteal All I'm saying is
AddNumbers 3
AddNumbers 4
AddNumbers 55

This doesn't really emphasize the time saving because it's such a small simple function, but with the longer stuff you just saved hours.
Abraham Breuer OP  @Reply  
     
5 years ago
okay helped

but how could you explain this:

Private Sub Status(S As String)
  
   StatusBox = S & vbNewLine & StatusBox
   DoEvents
  
End Sub
Private Sub Command0_Click()
  
    Dim db As Database
    Dim rs As Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("customerT")
    
    
    Status "------------------"
    Status db.Name
    Status rs.Name
    
    MsgBox db.Name
    MsgBox rs.Name
    
    rs.Close
    db.Close
    
    Set db = Nothing
    Set rs = Nothing

End Sub
Adam Schwanz  @Reply  
           
5 years ago
When you say "sending" it really is just as simple as it sounds, what you're basically doing is
FunctionName Value

That sends the Value to the FunctionName. Since we did (C As Integer) it is using C as sort of a place holder for an integer that we are going to tell it later on, and expecting us to supply that value when it's finally going to run the code. All we do to send it that value, is say the function name and then the value (and you should get one of those great little popups that tell you it's expecting a value for C after you type in: AddNumbers )
Abraham Breuer OP  @Reply  
     
5 years ago
so c is like dim but in a private sub
Adam Schwanz  @Reply  
           
5 years ago
Do you see what it's doing there now for S?

First Status is sending the ___________ then going to a new line and adding what was left before
   StatusBox = _________ & vbNewLine & StatusBox
   DoEvents

Second Status is sending the database name then going to a new line and adding what was left before
   StatusBox = DatabaseName & vbNewLine & StatusBox
   DoEvents

Third Status is sending the recordset name then going to a new line and adding what was left before.
   StatusBox = RecordsetName & vbNewLine & StatusBox
   DoEvents

Hopefully makes sense.
Abraham Breuer OP  @Reply  
     
5 years ago
thanks! got it

BTW what's the  ' & StatusBox ' ?
Adam Schwanz  @Reply  
           
5 years ago
You can kind of think of it as a Dim Yes, if you can imagine it working like

C = Code Given by the Button you pushed
Adam Schwanz  @Reply  
           
5 years ago
Value* not code
Richard Rost  @Reply  
           
5 years ago
StatusBox is a textbox field on the form. I'm adding to it with each call to the Status function, concatenating the new stuff to what's already in the box.
Abraham Breuer OP  @Reply  
     
5 years ago
so why when I don't put in this   ' & StatusBox '  it comes up only the last record (in a while loop)? it should of blank every think and add again the StatusBox?
Adam Schwanz  @Reply  
           
5 years ago
It comes up with just the recordset name right?
Scott Axton  @Reply  
        
5 years ago
Abraham -
     Status (S As String)  
could be written as
       Status (SomethingToPassToStatus as String)
In either case the "S" or the "SomethingToPassToStatus" is just a variable that is used to hold information in memory. S is just much easier
Another way to talk out the code - or a different method of thinking about it would be:
    Use the Status function and SUBSTITUTE in the next little bit as String (the stuff in quotes) which I'll call S

Given the line:  StatusBox = S & vbNewLine & StatusBox

and then further down in the code:
   Status "-----"

Another way to "talk this out loud" would be :
   I want the new value of StatusBox to be ( = ) a line of "-----" then I want to add on to that ( the & ) a Carriage Return and New Line ( vbNewLine ) then I want to add on to that ( the second & ) the value of whatever was previously in the StatusBox .

So if you want to start fresh or blank out the status box you would write:  
      StatusBox = ""
before you start your loop.


Scott Axton  @Reply  
        
5 years ago
if you leave off the ' & StatusBox ' you are telling the program:

Disregard what is in the StatusBox I now want the new value of StatusBox to be the last thing
I sent you.

So effectively you are blanking the StatusBox then putting the last Status command in it's place.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 15 Lessons.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/9/2026 3:54:30 PM. PLT: 1s