SQL query in VBA context

T

Ted

using a2k, i created a miniature mdb having most of the salient properties of
the production mdb but not all the controls.

i am interested in computing a followup visit date when the user inputs the
onstudydate of each person's onto the form provided.

there are two VBA codes i wrote to handle that scenario. one is in the
form's oncurrent event property and the other in the onstudydate's
afterupdate event property, as follows:

Option Compare Database
Private Sub Form_Current()
Dim Future_Visit As Date
If Not IsNull(Me.IRB_) Then Me.Future_Visit.Value = DLookup("FollowUp",
"Query4")
End Sub

Private Sub On_Study_Date_AfterUpdate()
Dim Future_Visit As Date
If Me.Dirty Then
If Not IsNull(Me.IRB_) Then
Me.Future_Visit.SetFocus
Me.Future_Visit.Value = DLookup("FollowUp", "Query5")
Me.On_Study_Date.SetFocus
End If
End If
End Sub


the two queries, 4 and 5 are as follows, respectively:

SELECT S.[Last Name], S.[First Name], S.[IRB#], S.[Study #], S.[Seq#],
S.Months, S.[On-Study Date], S.Schedule, S.[F/U Status], S.FollowUp
FROM [Sort By Month] AS S INNER JOIN Query3 AS Q ON (S.FollowUp=Q.NextVisit)
AND (S.[Last Name]=Q.[Last Name])
WHERE (((S.[Last Name])=[Forms]![Screening Log]![Last Name]));


SELECT S.[Last Name], S.[First Name], S.[IRB#], S.[Study #], S.[Seq#],
S.Months, S.[On-Study Date], S.Schedule, S.[F/U Status], S.FollowUp
FROM [Sort By Month] AS S INNER JOIN Query3 AS Q ON (S.[Last Name]=Q.[Last
Name]) AND (S.FollowUp=Q.NextVisit)
WHERE (((S.[Last Name])=[Forms]![Screening Log]![Last Name]) AND
((S.[On-Study Date])=[Forms]![Screening Log]![On-StudyDate]));

query4 works with the form's oncurrent event property as i intended for it:
each time a record is scrolled to, the correct future visit is generated and
appears on the user's data entry form.

query5 does not yet, however. it's intended (or so i lead myself to believe)
to compute the same quantity subject to the added criterion that query5 user
the just changed value of the onstudydate the user's made on the form.
perhaps that's a little too vague.....my goal is to beef up the form so that
when the user enters a value in the onstudydate control, (s)he will
immediately see the futurevisit date while still working on the same person's
record.

despite my newbie status, i think the achillees heel's in the query5.

thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top