# Thread: Combo box question (2003/All)

1. ## Combo box question (2003/All)

I have a form that records reading ages (RA) of children and the results are for a particular date (although the results may not be entered immediately).

To overcome a problem where the RA is compared to the chronological age (CA) of the student I want to use a combo box with the range 0-12 for the number of months that have passed since the test. The combo box (cmbRA_Diff) would apply a 'correction factor' to the difference between the RA and the CA. This difference uses some code provided by Hans. The age display on the form of the RA and the difference is in this format: <font color=blue>7.11 </font color=blue> being 7 years and 11 months and <font color=blue>-0.4</font color=blue> being an RA just four months behind chronological age.

My question is relating to 'capture' of the data for a particular date. I am unsure of how to use the combo box selection in the code.

My adaption of Hans' original code for one of the three years of RA capture is below.

<pre>Private Sub CalcDiff2()
Dim intPos1 As Integer
Dim intYr1 As Integer
Dim intMn1 As Integer
Dim intAg1 As Integer
Dim intPos2 As Integer
Dim intYr2 As Integer
Dim intMn2 As Integer
Dim intAg2 As Integer
Dim intDif As Integer
Dim strRes As String

If Not IsNull(Me.txtChronAge) And Not IsNull(Me.txtY2RA) Then
If txtY2RA.Value = "" Then Exit Sub
intPos1 = InStr(Me.txtChronAge, ".")
intYr1 = CInt(Left(Me.txtChronAge, intPos1 - 1))
intMn1 = CInt(Mid(Me.txtChronAge, intPos1 + 1))
intAg1 = 12 * intYr1 + intMn1
intPos2 = InStr(Me.txtY2RA, ".")
intYr2 = CInt(Left(Me.txtY2RA, intPos2 - 1))
intMn2 = CInt(Mid(Me.txtY2RA, intPos2 + 1))
intAg2 = 12 * intYr2 + intMn2
intDif = intAg2 - intAg1
If intDif < 0 Then
strRes = "-"
intDif = -intDif
End If
strRes = strRes & (intDif 12) & "." & (intDif Mod 12)
Me.txtY2RALev = strRes
End If

Exit Sub

End Sub</pre>

Any suggestions on how to achieve the application of a correction factor would be helpful.

2. ## Re: Combo box question (2003/All)

The line

<code> intDif = intAg2 - intAg1</code>

calculates the difference in months between RA and CA. Since your combo box will also be in months, you can subtract its value from intDif at this point:

<code> intDif = intAg2 - intAg1
If Not IsNull(Me.cmbRA_Diff) Then
intDif = intDif - Me.cmbRA_Diff
End If
If intDif < 0 Then
...
...</code>

or should it be added - getting confused now!