Evy Your wish is my command
Know that this is the code to create the form the Logic is to large to post
here.
Private Sub Combo82_AfterUpdate()
Application.VBE.MainWindow.Visible = False
Dim qsid As String
Dim rs As Recordset
Dim dbs As Database
Dim sql As String
Dim rcnt As Integer
Dim ctrl As Control
'Needed to dynamically create Q & A controls to allow text fields or
combo boxes
Dim frmOldForm As Form
Dim frmNewForm As Form
Dim strFormName As String, colwid As String
Dim ctlLabel As Control, ctlText As Control, Ctrldc As Control
Dim intDataX As Integer, intDataY As Integer
Dim intLabelX As Integer, intLabelY As Integer
Dim intLabelW As Integer, intLabelH As Integer
Dim X As Integer, questX As Integer, answerX As Integer
Dim cntrltype As String
Dim strSrchCrit As String
Dim strFormat As String
'Needed to dynamically create code module
Dim strDCAutoAns As String
Dim DCmdl As Module
Variables to dynamically create code module to refer to System Edits
Dim strWaltSEreference As String
Dim Waltmdl As Module
Dim lngReturn As Long
Me.ch_Signature.value = False 'Added to clear no signature box
Me.Spouse.value = False 'Added to clear spouse box
Me.New_Form.SourceObject = "aBaseForm"
'This retrieves all the questions available to the selected Question set
in the Combo82 combo box -
'the recordset is ordered by the quest_id field (ascending which is the
default)
Set dbs = CurrentDb
sql = "select quest_id, quest_text, answertype, format from questions
where question_set_id = '" & qsid & "' order by 1"
Set rs = dbs.OpenRecordset(sql)
If rs.EOF = True Then
MsgBox ("There are no questions in the selected question set.")
Exit Sub
End If
rs.MoveLast
rcnt = rs.RecordCount
ReDim NameArray(rcnt)
rs.MoveFirst
'The answertype field is either "T" for textboxes or "D" for combo boxes
and this field is placed into -
'an array in the order the recordset was created: by the question_id field
For X = 1 To rcnt
If Not rs.EOF Then
NameArray(X) = rs.Fields("answertype")
rs.MoveNext
End If
Next X
'Creates new sub-form
Set frmNewForm = CreateForm()
'Sets label Dimensions
intLabelW = 3750
intLabelH = 250
'Creates First Half Answers fields
For X = 1 To (Int(rcnt / 2))
' Set positioning values for new controls.
intDataX = 3900
intDataY = 100 * (4 * X) - 90
cntrltype = NameArray(X)
If cntrltype = "T" Then
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frmNewForm.Name, acTextBox, , "",
"", intDataX, intDataY)
ElseIf cntrltype = "D" Then
Set ctlText = CreateControl(frmNewForm.Name, acComboBox, , "",
"", intDataX, intDataY)
End If
Next X
'Creates Next Half of Answer fields
For X = (Int(rcnt / 2) + 1) To rcnt
' Set positioning values for new controls.
intDataX = 9500
intDataY = 100 * (4 * (X - (Int(rcnt / 2)))) - 90
cntrltype = NameArray(X)
If cntrltype = "T" Then
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frmNewForm.Name, acTextBox, , "",
"", intDataX, intDataY)
ElseIf cntrltype = "D" Then
Set ctlText = CreateControl(frmNewForm.Name, acComboBox, , "",
"", intDataX, intDataY)
End If
Next X
'Creates Fields for first half of Questions
For X = 1 To (Int(rcnt / 2))
' Set positioning values for new controls.
intLabelX = 50
intLabelY = 100 * (4 * X) - 90
Set ctlLabel = CreateControl(frmNewForm.Name, acLabel, , "", "",
intLabelX, intLabelY, intLabelW, intLabelH)
Next X
'Creates Fields for second half of Questions
For X = (Int(rcnt / 2) + 1) To rcnt
' Set positioning values for new controls.
intLabelX = 5500
intLabelY = 100 * (4 * (X - (Int(rcnt / 2)))) - 90
Set ctlLabel = CreateControl(frmNewForm.Name, acLabel, , "", "",
intLabelX, intLabelY, intLabelW, intLabelH)
Next X
strFormName = frmNewForm.Name
'Name Answer Controls
X = 1
For Each Ctrldc In frmNewForm.Controls
If Ctrldc.ControlType = acTextBox Or Ctrldc.ControlType = acComboBox
Then
Ctrldc.Name = ("A" & X)
Ctrldc.Properties("AfterUpdate") = "[Event Procedure]"
Ctrldc.Properties("BeforeUpdate") = "[Event Procedure]"
Set DCmdl = frmNewForm.Module
strWaltSEreference = "dim blnReturnValue as Boolean" & vbCrLf &
"blnReturnValue = ClassSystemEdits.SystemEdits" _
& vbCrLf & "If blnReturnValue = False then" & vbCrLf &
"docmd.cancelevent" & vbCrLf & "End If"
lngReturn = frmNewForm.Module.CreateEventProc("BeforeUpdate",
Ctrldc.Name)
frmNewForm.Module.InsertLines lngReturn + 1, vbTab &
strWaltSEreference
'GoToNextControl
Select Case Combo82.value
Case "Mag2K3", "Samp2K", "Mag2K1", "DE03", "DTC1206",
"HR03", "HR02", "PPAR3_TMSV", "PRE03", "REB04", "DB_SVY_06", "EXIT_LETTER",
"REB06", _
"W1_Mail", "W2_Mail", "W3_Mail", "FINE_PRINT", "PBRC04",
"2.50_SURV", "Samp02", "MAG2K5", "MORE", "MORE_USER", "TAZ_BRC", _
"CVT_WAVE3", "JUN05", "CVT_DWF2005", "CVT_DWF2006",
"HNV_SURV_SUMFALL05", "HNV_ENR_SUMFALL2005", "ORNC_BRC_05", "ORNC_DE_BRC",
"ABAT_05", "ORNC_DE_BRDOPTIN_BRC", _
"C_06", "BC_06", "C_HAQ", "WELCOME"
strDCAutoAns = "Private Sub A" & X & "_AfterUpdate()" _
& vbCrLf & "Call ClassDataEntryLogic.a" & X & "logic" &
vbCrLf & "End Sub" & vbCrLf & _
"Private Sub A" & X & "_Change()" & vbCrLf & "Call
ClassDataEntryLogic.GoToNextControl" & vbCrLf & _
"End Sub"
Case Else
strDCAutoAns = "Private Sub A" & X & "_AfterUpdate()" _
& vbCrLf & "Call ClassDataEntryLogic.a" & X & "logic" &
vbCrLf & "End Sub"
End Select
With DCmdl
.InsertText strDCAutoAns
End With
X = X + 1
End If
Next Ctrldc
'Names Question Controls
X = 1
For Each Ctrldc In frmNewForm.Controls
If Ctrldc.ControlType = acLabel Then
Ctrldc.Name = ("Q" & X)
X = X + 1
End If
Next Ctrldc
'Loads Values for answers
rs.MoveFirst
'Setup Column Widths
colwid = "0 In;1 In"
'The control tags are set to equal the question ID field
For Each Ctrldc In frmNewForm.Controls
If Ctrldc.ControlType = acTextBox Then
With Ctrldc
.BackColor = 8454143
.Tag = rs.Fields("quest_id")
End With
rs.MoveNext
'AnswerLookup is a function that creates the following SQL statement -
'= "select answer_data, answer_translated from question_valid_answers "
& _
'"where quest_id = " & qid
ElseIf Ctrldc.ControlType = acComboBox Then
With Ctrldc
.BackColor = 8454143
.ColumnCount = 2
.ColumnHeads = False
.BoundColumn = 1
.ColumnWidths = colwid
.LimitToList = True
.RowSource = AnswerLookup(rs.Fields("quest_id"))
.Tag = rs.Fields("quest_id")
End With
rs.MoveNext
End If
Next Ctrldc
'Loads Formats for All Answers
rs.MoveFirst
For Each Ctrldc In frmNewForm.Controls
If Ctrldc.ControlType = acTextBox Then
'setup search string
strSrchCrit = "[QUEST_ID] = " & Ctrldc.Tag
'begin searching
rs.FindFirst strSrchCrit
'Check if found
If rs.NoMatch Then
MsgBox "Matching Question Not Found"
Else
strFormat = rs!Format
Select Case strFormat
Case "D"
With Ctrldc
.InputMask = "99/99/9999;;_"
.DefaultValue = "12319999"
End With
Case "P"
With Ctrldc
.InputMask = "!\(999)\ 000\-0000;;_"
.DefaultValue = "9999999999"
End With
Case "M"
With Ctrldc
.Format = "Fixed"
.DecimalPlaces = "2"
.DefaultValue = "0.00"
End With
Case "R"
With Ctrldc
.Format = "Fixed"
.DecimalPlaces = "0"
.DefaultValue = "0"
End With
Case "N"
'Do Nothing
'Rest of the validation is placed in the Class System
Edits code
Case "A" 'will allow answers "1" or "0"
With Ctrldc
.ControlTipText = "A"
.AutoTab = True
.InputMask = "0;;"
End With
Case "B" 'will allow answers "1" or "0"
With Ctrldc
.ControlTipText = "B"
.AutoTab = True
.InputMask = "0;;"
End With
Case "C" 'age
With Ctrldc
.ControlTipText = "C"
.AutoTab = True
.InputMask = "00;;"
End With
Case Else
MsgBox "Unknown Case"
End Select
End If
End If
Next Ctrldc
' Load Values for Questions
' Added DoCmd.Maximize to correct minimizing problem with form
rs.MoveFirst
For Each Ctrldc In frmNewForm.Controls
If Ctrldc.ControlType = acLabel Then
With Ctrldc
.Caption = rs.Fields("quest_text")
.TextAlign = 3
End With
rs.MoveNext
End If
Next Ctrldc
frmNewForm.NavigationButtons = False
DoCmd.Close acForm, frmNewForm.Name, acSaveYes
DoCmd.Maximize
DoCmd.SetWarnings False
DoCmd.Rename "New_Form", acForm, strFormName
DoCmd.SetWarnings True
Me.New_Form.SourceObject = "New_Form"
p_source_code.value = ""
lblItemCode.Caption = ""
p_white_mail.value = ""
p_source_code.Requery ' attempt to clean up source code list
Call cmdClear_Click2
'Added to fix jump to new form
DATE_RECEIVED.SetFocus
Application.VBE.MainWindow.Visible = False
Exit Sub
errhand:
MsgBox (Err.Description)
End Sub