Results 1 to 4 of 4
  1. #1
    themidnitereign is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    11

    Need help making my code more efficient

    The rundown: I'm creating a database for collecting internal combustion engine data. I'm new to ms access and struggled through the one programming class I ever took. I managed to get this code working but I'm sure there is a more efficient way of doing what I want.



    I have two combo boxes and two tab controls. I only want the second combo box visible when certain values are selected and I only want pages on the tabs visible when certain values are selected again. I greatly appreciate any truncating that can be done.

    Code:
    Option Compare Database
    
    
    Private Sub Combo1_Change()
    
    'Makes all pages invisible
    For Each p In TabCtl_1.Pages
            p.Visible = False
            Next p
    For Each p In TabCtl_2.Pages
            p.Visible = False
            Next p
    
    'Make invisible unless selected
    If Combo1.Value = "Supercharged" Then
        TabCtl_1.Visible = True
        TabCtl_2.Visible = False
            
            ElseIf Combo1.Value = "Misc" Then
                TabCtl_2.Visible = True
                TabCtl_1.Visible = False
                    
                    Else
                        TabCtl_1.Visible = False
                        TabCtl_2.Visible = False
                    End If
    
    
    'Turn on selected page
            Select Case Combo1.Value
                Case "Bolt Ons"
                    Combo2.Value = ""
                        Combo2.Visible = True
                            ComboBox2_Label.Caption = "Bolt Ons"
                                Me.Combo2.RowSource = "Intake;Headers;Exhaust"
                Case "Internals"
                    Combo2.Value = ""
                        Combo2.Visible = True
                            ComboBox2_Label.Caption = "Internals"
                                Me.Combo2.RowSource = "Pistons;Rods;Crankshaft"
                Case "Ignition"
                    Combo2.Value = ""
                        Combo2.Visible = True
                            ComboBox2_Label.Caption = "Ignition"
                                Me.Combo2.RowSource = "Spark Plaugs;Coils;Wires"
                                
                Case "Supercharged"
                    Page4.Visible = True
                    Combo2.Visible = False
                    
                Case "Misc"
                    Page8.Visible = True
                    Combo2.Visible = False
            End Select
    
    
    End Sub
    
    
    Private Sub Combo2_Change()
    
    ' Turn off pages in top tab
    For Each p In TabCtl_1.Pages
        p.Visible = False
            Next p
    
    ' Turn off pages in bottom tab
    For Each p In TabCtl_2.Pages
        p.Visible = False
            Next p
    
    'Turn on/off top tab border
    If Combo2.Value = "Intake" Or Combo2.Value = "Headers" Or Combo2.Value = "Exhaust" Then
        TabCtl_1.Visible = True
            Else
        TabCtl_1.Visible = False
            End If
    
    'Turn on/off bottom tab border
    If Combo2.Value = "Pistons" Or Combo2.Value = "Rods" Or Combo2.Value = "Crankshaft" Then
        TabCtl_2.Visible = True
            Else
        TabCtl_2.Visible = False
            End If
    
    'Turn on selected page
    Select Case Combo2.Value
        Case "Intake"
            Page1.Visible = True
        Case "Headers"
            Page2.Visible = True
        Case "Exhaust"
            Page3.Visible = True
        Case "Pistons"
            Page5.Visible = True
        Case "Rods"
            Page6.Visible = True
        Case "Crankshaft"
            Page7.Visible = True
    End Select
    
    
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That looks good to me and if it ain't broke ...

    Really, for someone who claims to have struggled through programming class, you make it look like you know what you are doing.

    Changes might improve readability. I like to line up the Else and End If and Next lines with the If and For lines. Also the 'stair-stepping' is a bit overdone in the Case sequence.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with June7 -- nice code and formatting from someone who struggled with programming.

    What makes you think it's inefficient?
    We don't know anything of your database structure.

  4. #4
    themidnitereign is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    11
    Thanks for the confidence boost guys!
    I thought maybe there would be some way to turn some of the cases and loops into less code by using arrays/strings. I figured I was coding like a kindergartner but if you guys like it then I'll keep it as is. Thanks again, guys!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. More efficient way to create a query?
    By Kirsti in forum Queries
    Replies: 3
    Last Post: 07-04-2012, 10:36 PM
  2. Replies: 1
    Last Post: 06-19-2012, 06:12 PM
  3. More efficient way of repeating code
    By karmacable in forum Programming
    Replies: 2
    Last Post: 09-12-2011, 12:43 AM
  4. Efficient Process?
    By compooper in forum Database Design
    Replies: 1
    Last Post: 06-14-2011, 03:01 PM
  5. Are text primary keys less efficient than autonumbers?
    By bar tomas in forum Database Design
    Replies: 4
    Last Post: 05-11-2009, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums