Question : Speed up loading of form loaded with text boxs

I have some forms that are loaded with textboxs that create a tournament bracket, i am populating the form from the form_open event that calls a Public function that sits in a Module... Currently the form is populated by querying the recordset of players for the tournament choosen, i was wondering if anyone can me me a faster way of populating the form.. it currently takes about a second and half to open...but i think it should be faster, or without any lag. i have attached a picture of the form, and the code that populates the form...

thanks for any ideas that you might provide.

right now i have 4 forms (or Brackets that i am using)

a 16 player Double elimination form
a 32 player double elim form
a 64 player single
and a 32 single form.

i have included a picture of the 32 player double elimination form.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
Public Function PopulateForms(strForm As String)
Dim strSelect As String
Dim rst As DAO.Recordset
Dim dbs As Database
Dim ctl As Control
Dim strName As String
Dim dblTID As Double
Dim dblchart As Double
Dim dblH As Double
Dim dblW As Double
Dim L As Integer
Dim txtCR As Control, txtC As String, txtRange As String
Dim opt1 As Long, opt2 As Long, opt3 As Long, opt4 As Long, opt5 As Long, opt6 As Long, opt7 As Long, opt8 As Long, opt9 As Long
Dim I As Integer

I = 0

Set dbs = CurrentDb
    
    dblTID = Forms!fTournament.cboTour
    Forms(strForm).Controls("txtTID") = dblTID

    dblchart = DLookup("tChart", "tTournaments", "TID = " & dblTID)
    
    Select Case dblchart
        Case 16, 32
                dblH = 240
        Case Else
                dblH = 180
    End Select
    
    Select Case strForm

        Case "f32PlayerDouble"
            dblW = 1320
        Case Else
            dblW = 1440
    End Select
    
        opt1 = DLookup("ColorValue", "tFormats", "FID = 1") 'Players With Byes
        opt2 = DLookup("ColorValue", "tFormats", "FID = 2") 'Bye Positions
        opt3 = DLookup("ColorValue", "tFormats", "FID = 3") 'In Progress
        opt4 = DLookup("ColorValue", "tFormats", "FID = 4") 'Players Waiting
        opt5 = DLookup("ColorValue", "tFormats", "FID = 5") 'Matches Finished
        opt6 = DLookup("ColorValue", "tFormats", "FID = 6") 'Background Color
        opt7 = DLookup("ColorValue", "tFormats", "FID = 7") 'Bracket Lines
        opt8 = DLookup("ColorValue", "tFormats", "FID = 8") 'Border Colors
        opt9 = DLookup("ColorValue", "tFormats", "FID = 9") 'Not In Use
        
          
Forms(strForm).Detail.BackColor = opt6

                
          strSelect = "SELECT tTextBoxControls.TextBoxName, tTournamentDetails.PID, tTournamentDetails.DrawNo, tTextBoxControls.txtID, tTournamentDetails.Completed, tTournamentDetails.PID AS PLID," _
            & " DLookUp(""PlayerName"",""tPlayers"",""PID = "" & [PID]) AS Player, DLookUp(""HC"",""tPlayers"",""PID = "" & [PID]) AS HCap" _
            & " FROM tTournamentDetails INNER JOIN tTextBoxControls ON tTournamentDetails.txtID = tTextBoxControls.txtID" _
            & " WHERE (((tTournamentDetails.TID)= " & dblTID & "));"
                
         
    Set rst = dbs.OpenRecordset(strSelect, dbOpenSnapshot, dbReadOnly, dbReadOnly)
  
While Not rst.EOF

'        'For Each txtCR In Forms(strForm)
'
'                If txtCR.ControlType = acTextBox Then
'                            If txtCR.Name = rst!TextBoxName Then
                            
                            If Not IsNull(rst!TextBoxName) Then
 
                                    If Len(rst!Player) > L Then
                                            I = InStr(1, rst!Player, " ", 0)
                                            strName = "  " & Left(rst!Player, I + 1) & ".  " & rst!HCap
              
                                    Else
                                            strName = "  " & rst!Player & "  " & rst!HCap
                      
                                    End If
                                
                                    Forms(strForm).Controls(rst!TextBoxName) = strName
                 
                                    Forms(strForm).Controls(rst!TextBoxName).Tag = rst!PID

                                    Select Case rst!completed
                                    
                                        Case -1 'Players With Byes
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .BackColor = opt5
                                                .BorderStyle = 1
                                                .BackStyle = 1
                                                .BorderColor = opt8
                                            End With
                                        Case -2  'Bye Positions
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .ForeColor = 255
                                                .TextAlign = 2
                                                .Value = rst!Player
                                                .Width = dblW
                                                .BorderColor = opt8
                                                .BorderStyle = 1
                                                .BackStyle = 1
                                                .BackColor = opt2
                                                .Height = dblH
                                            End With
                                        Case -3 'Matches in Progress
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .ForeColor = 0
                                                .TextAlign = 2
                                                .Value = Nz(rst!Player, "")
                                                .Width = dblW
                                                .BorderColor = opt8
                                                .BorderStyle = 1
                                                .BackStyle = 1
                                                .BackColor = opt3
                                                .Height = dblH
                                            End With
                                        Case -4 'Players Waiting
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .ForeColor = 0
                                                .TextAlign = 1
                                                .Width = dblW
                                                .BorderStyle = 1
                                                .BorderColor = opt8
                                                .BackStyle = 1
                                                .BackColor = opt4
                                                .Height = dblH
                                                .ControlTipText = Nz(rst!Player, "")
                                            End With
                                        Case -5  'Matches Finished
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .ForeColor = 0
                                                .TextAlign = 1
                                                .Width = dblW
                                                .BorderStyle = 1
                                                .BorderColor = opt8
                                                .BackStyle = 1
                                                .BackColor = opt5
                                                .Height = dblH
                                                .ControlTipText = Nz(rst!Player, "")
                                               End With
                                        Case -9 'Not In Use
                                            With Forms(strForm).Controls(rst!TextBoxName)
                                                .ForeColor = 0
                                                .TextAlign = 1
                                                .Width = dblW
                                                .BorderStyle = 1
                                                .BorderColor = opt8
                                                .BackStyle = 1
                                                .BackColor = opt9
                                                .Height = dblH
                                                .ControlTipText = Nz(rst!Player, "")
                                            End With
                                        End Select
                            End If
                End If

'                        If Forms(strForm).ControlType = acLine Then
'                                with
'                                    .BorderStyle = 1
'                                    .BorderColor = opt7
'                        End If
                        
Next
   
        rst.MoveNext
        Wend
    rst.Close
    
    Set rst = Nothing
    Set dbs = Nothing
    

End Function

Answer : Speed up loading of form loaded with text boxs

In essence, each DLookup() is opening a recordset, finding a record and returning a value  ( see http://www.experts-exchange.com/articles/Microsoft/Development/MS_Access/Dlookup-and-the-Domain-Functions.html)

So ... just open a recordset once, and populate an array or collection.

mx
Random Solutions  
 
programming4us programming4us