Quote:
Originally Posted by Thinker
Much, much easier to just use a label control array. Since you will
already have at least one label on your form, it just doesn't make any
sense to use this very esoteric method of adding controls at runtime.
I use the standard control array method in this example...
http://www.xtremevbtalk.com/show...threadid=20002
It queries the table for the number of fields and adds controls to match.
I used For loop code from the Sub Form_Load that was included in your sample program. Is the For Loop all I need to populate the labels and add a new lable to the form? When I run the code is throws up an error: 360 Oject already loaded. I'm not sure where to include the code. Can you help me out? Thanks
Private Sub GetNew214Info()
' Get info from new Carrier214 table
'
Dim rsNew As ADODB.Recordset
Dim sSQL As String
Dim i As Integer
Dim temp As String, xx As Integer
'
On Error GoTo GetNew214Info_Err
'
' Setup SQL statement
sSQL = "SELECT SCAC, Enabled, LastFeed, NumberFeeds " & _
"From CarrierTable " & _
"Where (Enabled = 1) " & _
"ORDER BY LastFeed DESC "
'
' Open Recordset
If Open_ADORS(cnShipStatDB, rsNew, sSQL) = True Then
'
' Check Record Count to inture there were records found
If rsNew.RecordCount > 0 Then
' Records found
'
rsNew.MoveFirst
i = 0
' Loop through records and insert information into form labels
Do While rsNew.EOF = False
For xx = 0 To rsNew.Fields.Count - 1
If xx > 0 Then
Load frmWatch.lblNewSCAC(xx)
Load frmWatch.lblLastEntry(xx)
Load frmWatch.lblNumber(xx)
frmWatch.lblNewSCAC(xx).Top = frmWatch.lblNewSCAC(xx - 1).Top + 400
frmWatch.lblLastEntry(xx).Top = frmWatch.lblLastEntry(xx - 1).Top + 400
frmWatch.lblNumber(xx).Top = frmWatch.lblNumber(xx - 1).Top + 400
frmWatch.lblNewSCAC(xx).Visible = True
frmWatch.lblLastEntry(xx).Visible = True
frmWatch.lblNumber(xx).Visible = True
End If
Next xx
frmWatch.lblNewSCAC(i).Caption = rsNew.Fields("SCAC")
frmWatch.lblLastEntry(i).Caption = rsNew.Fields("LastFeed")
frmWatch.lblNumber(i).Caption = rsNew.Fields("NumberFeeds")
i = i + 1
rsNew.MoveNext
DoEvents
Loop
Else
' no records in RS
MsgBox "No records found in Recordset.", vbOKOnly
End If
' Close Recordset
Call Close_ADORS(rsNew)
End If
'
Exit Sub
'
GetNew214Info_Err:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
'
End Sub