Do Loop Error

kermit5

Registered User.
Local time
Today, 04:52
Joined
Nov 2, 2001
Messages
122
Here is my code. It worked fine until I revised my code to define my control's default values. Now I get a compile error: Loop without Do. Any idea what I am missing?

Private Sub cmdDetailsNext_Click()

Dim ctlLabel As control, ctlControl As control, ctlName As Variant
Dim fld As Object
Dim intLabelX As Integer, intLabelY As Integer
Dim intDataX As Integer, intDataY As Integer
Dim intTabIndex As Integer
Dim frmTakeoff As Form
Dim rstSelectedField As DAO.Recordset
Dim dbs As DAO.Database
Dim qd As DAO.QueryDef
Dim txtProjectName As String

TxtProjectID = Forms!frmDetails!TxtProjectID
txtProjectName = Forms!frmDetails!txtProjectName
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qryCreateForm
qd.Parameters![Master Project ID] = TxtProjectID
Set rstSelectedField = qd.OpenRecordset

'Open "frmCustomForm" form in design view
DoCmd.OpenForm "frmCustomTakeoff", acDesign
Set frmTakeoff = Forms!frmCustomTakeoff

DoCmd.Hourglass (True)

' Set positioning values for new controls
intTabIndex = 0
intLabelX = 100
intLabelY = 550
intDataX = 100
intDataY = 0
Do While Not rstSelectedField.EOF
ctlName = rstSelectedField("SelectedField")
Set ctlControl = CreateControl(frmTakeoff.Name, rstSelectedField("FieldControlType"), , , ctlName, intDataX, intDataY)
'Create child label control for text box
Set ctlLabel = CreateControl(frmTakeoff.Name, acLabel, acHeader, ctlName, ctlName, intLabelX, intLabelY)
'Set Default Values
If IsNull(rstSelectedField.Fields("DefaultValue")) Then
If Not IsNull(rstSelectedField.Fields("FieldDefaultValue")) Then
ctlControl.DefaultValue = rstSelectedField.Fields("FieldDefaultValue")
Else: ctlControl.DefaultValue = rstSelectedField.Fields("DefaultValue")
End If
'Check for Control Type 111 (Combo Box)
If rstSelectedField.Fields("FieldControlType") = 111 Then
ctlControl.OnKeyDown = "[Event Procedure]"
'Set Row Source Type and Values
If Not IsNull(rstSelectedField.Fields("FieldRowSource")) Then
ctlControl.RowSourceType = "Value List"
ctlControl.RowSource = rstSelectedField.Fields("FieldRowSource")
End If
End If
'Move to next location
intLabelX = intLabelX + rstSelectedField("FieldSize") + 50
intDataX = intDataX + rstSelectedField("FieldSize") + 50
'Define Control Properties
ctlControl.Name = rstSelectedField("FieldTitle")
ctlControl.Width = rstSelectedField("FieldSize")
ctlControl.TabIndex = intTabIndex
intTabIndex = intTabIndex + 1

'Define Label Properties
ctlLabel.Width = rstSelectedField("FieldSize")
'Restore form
'DoCmd.Restore
rstSelectedField.MoveNext
Loop

DoCmd.OpenForm "frmCustomTakeoff", acNormal
Forms!frmCustomTakeoff!TxtProjectID = TxtProjectID
Forms!frmCustomTakeoff!txtProjectName = txtProjectName
DoCmd.Maximize
DoCmd.Hourglass (False)
DoCmd.Close acForm, "frmDetails"
End Sub


Any help would be greatly appreciated!
Scott
 
Count the number of IF and END IF inside your loop. I think you are missing one END IF...
 

Users who are viewing this thread

Back
Top Bottom