D
Duncan Edment
I have a ComboBox on a form, that lists projects. These
projects come from a table with the following definition:
tblProjects
fldProjectID = Number
fldProjectDesc = Text
fldValidUntil = Date / Time
The theory is that each project has a valid until date,
after which the project can no longer be selected. i.e.
ProjectAlpha has a ValidUntilDate of 20/05/04, so work can
be recorded against this project up until this date, but
not after.
The "AfterUpdate" event of the project description control
has the following code:
Private Sub txtProjectID_AfterUpdate()
Dim datCRecDate As Date
Dim datWkStart As Date
Dim datWkEnd As Date
Dim rstPrevious As DAO.Recordset
Dim db As DAO.Database
Dim strSQL As String
Dim strMsgText As String
strSQL = "SELECT * from tblProjects " & _
"WHERE fldProjectID = " & txtProjectID.Value & _
";"
Set db = CurrentDb
Set rstPrevious = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rstPrevious!fldValidUntilDate.Value < Date Then
strMsgText = rstPrevious!fldProjectDescription.Value
MsgBox "I am sorry, but the project code" & vbCrLf & _
vbCrLf & "'" & strMsgText & "'" & vbCrLf & vbCrLf & _
"is no longer valid." & vbCrLf & vbCrLf & _
"Please select a valid entry", vbExclamation, _
"!! Out of date code !!"
Me.Undo
txtProjectID.SetFocus
End If
Set rstPrevious = Nothing
End Sub
This seems to work fine...if an out-of-date code is
selected, the msgbox displays. Everything fine so far.
However, what I now want to do is limit the display in the
ComboBox, so that projects that have a "ValidUntiLDate" in
the past, will not be displayed. In the 'RowSource' for
the Combo control, I have the following:
SELECT [tblProjects].[fldProjectDescription], _
[tblProjects].[fldProjectID] FROM tblProjects WHERE _
((([tblProjects].[fldValidUntilDate])>Date()));
This seems to work fine, except that where the project has
genuinely been selected, it no longer appears on the
form. For records that have the project against them,
with a DateWorked in the past, the Project Combo Control
is blank.
Can someone help me?
Many thanks
Duncan
projects come from a table with the following definition:
tblProjects
fldProjectID = Number
fldProjectDesc = Text
fldValidUntil = Date / Time
The theory is that each project has a valid until date,
after which the project can no longer be selected. i.e.
ProjectAlpha has a ValidUntilDate of 20/05/04, so work can
be recorded against this project up until this date, but
not after.
The "AfterUpdate" event of the project description control
has the following code:
Private Sub txtProjectID_AfterUpdate()
Dim datCRecDate As Date
Dim datWkStart As Date
Dim datWkEnd As Date
Dim rstPrevious As DAO.Recordset
Dim db As DAO.Database
Dim strSQL As String
Dim strMsgText As String
strSQL = "SELECT * from tblProjects " & _
"WHERE fldProjectID = " & txtProjectID.Value & _
";"
Set db = CurrentDb
Set rstPrevious = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rstPrevious!fldValidUntilDate.Value < Date Then
strMsgText = rstPrevious!fldProjectDescription.Value
MsgBox "I am sorry, but the project code" & vbCrLf & _
vbCrLf & "'" & strMsgText & "'" & vbCrLf & vbCrLf & _
"is no longer valid." & vbCrLf & vbCrLf & _
"Please select a valid entry", vbExclamation, _
"!! Out of date code !!"
Me.Undo
txtProjectID.SetFocus
End If
Set rstPrevious = Nothing
End Sub
This seems to work fine...if an out-of-date code is
selected, the msgbox displays. Everything fine so far.
However, what I now want to do is limit the display in the
ComboBox, so that projects that have a "ValidUntiLDate" in
the past, will not be displayed. In the 'RowSource' for
the Combo control, I have the following:
SELECT [tblProjects].[fldProjectDescription], _
[tblProjects].[fldProjectID] FROM tblProjects WHERE _
((([tblProjects].[fldValidUntilDate])>Date()));
This seems to work fine, except that where the project has
genuinely been selected, it no longer appears on the
form. For records that have the project against them,
with a DateWorked in the past, the Project Combo Control
is blank.
Can someone help me?
Many thanks
Duncan