unable to get 2nd & 3rd column value from combobox

  • Thread starter Thread starter Kaoli
  • Start date Start date
K

Kaoli

I have a unbound combobox(cboPeriod) in header, I call the recordsource from
a table call tblPeriod which contain 3 fields 1st
[Period],2nd[FromDate],3rd[ToDate]

I have a validation which transaction date must within the FromDate and ToDate
but when I do as per below,

Let say in cboPeriod value = 201004(1st Value), 1/4/2010(2nd
value),30/4/2010(3rd Value)
1st Part to fill in the Yearmonth =me.cboperiod is ok, I can get the value
as 201004

but 2nd Part to validate the date with 1/4/2010 & 30/4/2010 I unable to get
the value, which return the value null.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.YearMonth) Then
Me.YearMonth = Me.CboPeriod
Else
End If

If Me.TranDate < Me.CboPeriod.column(1) Or Me.TranDate >
Me.CboPeriod.column(2) Then
MsgBox "Date not within the Period."
Cancel = True
End If
End Sub
 
make sure you have 3 in the 'number of columns' property of the combo box.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
Dear Dorian,

Do you mean Column Count?
Yes I already set Column Count 3

Dorian said:
make sure you have 3 in the 'number of columns' property of the combo box.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


Kaoli said:
I have a unbound combobox(cboPeriod) in header, I call the recordsource from
a table call tblPeriod which contain 3 fields 1st
[Period],2nd[FromDate],3rd[ToDate]

I have a validation which transaction date must within the FromDate and ToDate
but when I do as per below,

Let say in cboPeriod value = 201004(1st Value), 1/4/2010(2nd
value),30/4/2010(3rd Value)
1st Part to fill in the Yearmonth =me.cboperiod is ok, I can get the value
as 201004

but 2nd Part to validate the date with 1/4/2010 & 30/4/2010 I unable to get
the value, which return the value null.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.YearMonth) Then
Me.YearMonth = Me.CboPeriod
Else
End If

If Me.TranDate < Me.CboPeriod.column(1) Or Me.TranDate >
Me.CboPeriod.column(2) Then
MsgBox "Date not within the Period."
Cancel = True
End If
End Sub
 
Kaoli said:
I have a unbound combobox(cboPeriod) in header, I call the recordsource
from
a table call tblPeriod which contain 3 fields 1st
[Period],2nd[FromDate],3rd[ToDate]

I have a validation which transaction date must within the FromDate and
ToDate
but when I do as per below,

Let say in cboPeriod value = 201004(1st Value), 1/4/2010(2nd
value),30/4/2010(3rd Value)
1st Part to fill in the Yearmonth =me.cboperiod is ok, I can get the value
as 201004

but 2nd Part to validate the date with 1/4/2010 & 30/4/2010 I unable to
get
the value, which return the value null.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.YearMonth) Then
Me.YearMonth = Me.CboPeriod
Else
End If

If Me.TranDate < Me.CboPeriod.column(1) Or Me.TranDate >
Me.CboPeriod.column(2) Then
MsgBox "Date not within the Period."
Cancel = True
End If
End Sub
 
i dint get where you are do the validation

it is with in the selection of the pick-list

in any way i hope the code below can help :

Private Sub test()

Dim Xdate1 As Date
Dim Xdate2 As Date
Dim Edate As Date

Xdate1 = "01/01/2010"
Xdate2 = "30/03/2010"
Edate = "03/06/2010"

YearMonth = Year(Xdate1 ) & Month(Xdate1 )

If IsNull(YearMonth) Then

YearMonth = YearMonth

End If

If Edate >= Xdate1 And Edate <= Xdate2 Then
MsgBox "Date not within the Period."
Cancel = True
End If
 
Back
Top