Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > Courses > Access > Developer > D19 > D19 Lessons < D18 Lessons | D20 Lessons >
Back to Access Developer 19 Lessons    Comments List
If Then for New Customers Upload Images   Link   Email  
JP von der Borch 
ifThenElse added into code below enables new records (customers) in main form

Private Sub Form_Current()
    ' clear listbox
    Dim X As Long
    Dim db As Database
    Dim rs As Recordset
          
    For X = 0 To ProductList.ListCount - 1
        ProductList.Selected(X) = False
    Next
    'loop through records for this customer
    Set db = CurrentDb

    'Null CustomerID on the form occurs when clicking through past last record to 'New' record
    '....so for 'New' record, SQL will load all from CustomerRecordT and then exit sub.
   If IsNull(Me.CustomerID) Then
            Set rs = db.OpenRecordset("SELECT * FROM CustomerInterestT")
            Exit Sub  'exit sub here if 'new' record otherwise WhileWend loop below will select items in listbox
    Else
        'SQL includes the WHERE statement when the active form has a CustomerID
        Set rs = db.OpenRecordset("SELECT * FROM CustomerInterestT WHERE CustomerID=" & CustomerID)
    End If

    'select the items in the list box that are included in the CustomerInterestT for the customer
    While Not rs.EOF
            For X = 0 To ProductList.ListCount - 1
                If CLng(ProductList.Column(0, X)) = rs!ProductID Then     'ListBoxes always return text i.e. "1"  
                    ProductList.Selected(X) = True
                End If
            Next
        rs.MoveNext
    Wend
    
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
End Sub
Richard Rost 
Thanks for sharing, JP!

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

 
 
 

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 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 7:53:25 AM. PLT: 0s