Repost: Calendar change needs to requery subform

C

CJ

This was originally posted yesterday, November 16. However, due to the
unhelpful response I received it looks like my questions were answered. My
questions were not answered so here I go again....... Thanks for your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the date on the
calendar of my main form as criteria.......my thought being that when the
date on the calendar changes then the date of the query changes as well.

I added a requery statement to the On Updated event of the calendar, but the
subform will not change until I hit enter and then it also moves to the first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??
 
G

Graham Mandeno

Hi CJ

As you have discovered, a Requery will always reset to the first record.
What you need to do is store the primary key value of the subform's current
record before the requery, then do a FindFirst to reposition the record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With
 
C

CJ

Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the transactions an
employee made for the day at a particular store. Since an employee can work
at different branches, I have used lngProjectID and lngEmpID as my link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make finding a
date easier for the end users. If there is a better way, then please let me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

As you have discovered, a Requery will always reset to the first record.
What you need to do is store the primary key value of the subform's current
record before the requery, then do a FindFirst to reposition the record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
This was originally posted yesterday, November 16. However, due to the
unhelpful response I received it looks like my questions were answered. My
questions were not answered so here I go again....... Thanks for your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the date on
the
calendar of my main form as criteria.......my thought being that when the
date on the calendar changes then the date of the query changes as well.

I added a requery statement to the On Updated event of the calendar, but
the
subform will not change until I hit enter and then it also moves to the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
G

Graham Mandeno

Hi CJ

What this means is that the value of lngProjectID in the current record of
your subform is Null. If this is the case, then surely it is meaningless to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store (lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows additions and
you are on a new record).

Further, if you have just changed the date in the calendar then surely the
record which was current on the subform before (corresponding to the old
date) will no longer be included in the list for the newly selected date, so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the transactions an
employee made for the day at a particular store. Since an employee can
work
at different branches, I have used lngProjectID and lngEmpID as my link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make finding a
date easier for the end users. If there is a better way, then please let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

As you have discovered, a Requery will always reset to the first record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
This was originally posted yesterday, November 16. However, due to the
unhelpful response I received it looks like my questions were answered.
My
questions were not answered so here I go again....... Thanks for your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the date
on
the
calendar of my main form as criteria.......my thought being that when
the
date on the calendar changes then the date of the query changes as
well.

I added a requery statement to the On Updated event of the calendar,
but
the
subform will not change until I hit enter and then it also moves to the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
C

CJ

Hi:

Sorry, I had a couple of requery statements that were causing grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in the
calendar not a single thing happens. I was thinking that the date from the
calendar would have to be criteria in the subform query, but the Calendar
Control does not show up when I use the build button to add criteria for the
date field.

I guess I am expecting the transactions for the current employee to filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form, should it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

What this means is that the value of lngProjectID in the current record of
your subform is Null. If this is the case, then surely it is meaningless to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store (lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows additions and
you are on a new record).

Further, if you have just changed the date in the calendar then surely the
record which was current on the subform before (corresponding to the old
date) will no longer be included in the list for the newly selected date, so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the transactions an
employee made for the day at a particular store. Since an employee can
work
at different branches, I have used lngProjectID and lngEmpID as my link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make finding a
date easier for the end users. If there is a better way, then please let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

As you have discovered, a Requery will always reset to the first record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However, due to the
unhelpful response I received it looks like my questions were answered.
My
questions were not answered so here I go again....... Thanks for your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the date
on
the
calendar of my main form as criteria.......my thought being that when
the
date on the calendar changes then the date of the query changes as
well.

I added a requery statement to the On Updated event of the calendar,
but
the
subform will not change until I hit enter and then it also moves to the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
G

Graham Mandeno

Hi CJ

Unbound controls do not appear in the link fields wizard, but they can be
used (for master only, not child). I'm not sure if an unbound calendar
control can be used in LinkMasterFields (I've never tried) but if it can't
then a textbox certainly can. You can set the ControlSource of a textbox to
=[CalCtl1] and then use the textbox as your LinkMasterFields component.

The approach you should use here depends on your needs. You can either
have:

a) a subform showing ONLY the transactions for a given employee, project,
and date (all three must be selected)

or

b) what I call a "progressive filter" - all transactions are shown, but when
an employee is selected from a combo box (or a project, or a date) the list
is filtered accordingly. So you could show all transactions for a given
ProjectID, or for a given EmployeeID on a given date, or whatever.

The first option simply uses a subform with three paired fields as a link.
This is simple, but I think it is not very flexible or user-friendly as all
three criteria need to be specified.

The second option doesn't even require a subform - just a continuous form -
and the AfterUpdate events for each of your three "selection controls"
builds a filter string and applies it to the form.

I'll give you some more details on the second option if you're interested in
that approach.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi:

Sorry, I had a couple of requery statements that were causing
grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the
subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in the
calendar not a single thing happens. I was thinking that the date from the
calendar would have to be criteria in the subform query, but the Calendar
Control does not show up when I use the build button to add criteria for
the
date field.

I guess I am expecting the transactions for the current employee to filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form, should
it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

What this means is that the value of lngProjectID in the current record
of
your subform is Null. If this is the case, then surely it is meaningless
to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store
(lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows additions
and
you are on a new record).

Further, if you have just changed the date in the calendar then surely
the
record which was current on the subform before (corresponding to the old
date) will no longer be included in the list for the newly selected date,
so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my
confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the transactions
an
employee made for the day at a particular store. Since an employee can
work
at different branches, I have used lngProjectID and lngEmpID as my link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make finding
a
date easier for the end users. If there is a better way, then please
let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

As you have discovered, a Requery will always reset to the first
record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the
record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However, due to
the
unhelpful response I received it looks like my questions were
answered.
My
questions were not answered so here I go again....... Thanks for
your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the
date
on
the
calendar of my main form as criteria.......my thought being that
when
the
date on the calendar changes then the date of the query changes as
well.

I added a requery statement to the On Updated event of the calendar,
but
the
subform will not change until I hit enter and then it also moves to
the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
C

CJ

Hi Graham, thanks for the options.

I think I just about have a modified option 2 in place already.

1. This form opens as a filter from the main Project form, so you don't have
the option to see data for other stores from here.
2. I have a combo box that searches for the employees of the particular
store and shows all of their transactions in the subform.
3. I only need the calendar to filter the subform by the selected date.

Thanks a million for all of your efforts.
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

Unbound controls do not appear in the link fields wizard, but they can be
used (for master only, not child). I'm not sure if an unbound calendar
control can be used in LinkMasterFields (I've never tried) but if it can't
then a textbox certainly can. You can set the ControlSource of a textbox to
=[CalCtl1] and then use the textbox as your LinkMasterFields component.

The approach you should use here depends on your needs. You can either
have:

a) a subform showing ONLY the transactions for a given employee, project,
and date (all three must be selected)

or

b) what I call a "progressive filter" - all transactions are shown, but when
an employee is selected from a combo box (or a project, or a date) the list
is filtered accordingly. So you could show all transactions for a given
ProjectID, or for a given EmployeeID on a given date, or whatever.

The first option simply uses a subform with three paired fields as a link.
This is simple, but I think it is not very flexible or user-friendly as all
three criteria need to be specified.

The second option doesn't even require a subform - just a continuous form -
and the AfterUpdate events for each of your three "selection controls"
builds a filter string and applies it to the form.

I'll give you some more details on the second option if you're interested in
that approach.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi:

Sorry, I had a couple of requery statements that were causing
grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the
subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in the
calendar not a single thing happens. I was thinking that the date from the
calendar would have to be criteria in the subform query, but the Calendar
Control does not show up when I use the build button to add criteria for
the
date field.

I guess I am expecting the transactions for the current employee to filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form, should
it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

What this means is that the value of lngProjectID in the current record
of
your subform is Null. If this is the case, then surely it is meaningless
to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store
(lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows additions
and
you are on a new record).

Further, if you have just changed the date in the calendar then surely
the
record which was current on the subform before (corresponding to the old
date) will no longer be included in the list for the newly selected date,
so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my
confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the transactions
an
employee made for the day at a particular store. Since an employee can
work
at different branches, I have used lngProjectID and lngEmpID as my link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make finding
a
date easier for the end users. If there is a better way, then please
let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

As you have discovered, a Requery will always reset to the first
record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the
record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However, due to
the
unhelpful response I received it looks like my questions were
answered.
My
questions were not answered so here I go again....... Thanks for
your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the
date
on
the
calendar of my main form as criteria.......my thought being that
when
the
date on the calendar changes then the date of the query changes as
well.

I added a requery statement to the On Updated event of the calendar,
but
the
subform will not change until I hit enter and then it also moves to
the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
G

Graham Mandeno

Hi CJ

OK, then you are currently linking the main and sub-forms using TWO fields -
ProjectID and EmpID, correct?

What you need to do is apply a filter to the subform when a date is selected
in the calendar:

Private Sub CalCtl1_AfterUpdate()
Dim sbf as Form
*Dim SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
*SavedID = Nz(sbf!ID, 0) ' take care of possible null
With sbf
.Filter = "[TransactionDate]=" _
& Format(CalCtl1.Value, "\#mm/dd/yyyy\#")
.FilterOn = True
End With
*With sbf.RecordsetClone
* .FindFirst "ID=" & SavedID
* If Not .NoMatch then sbf.Bookmark = .Bookmark
*End With
End Sub

Note that we are using the AfterUpdate event, not Updated. The Updated
event is not supported, even though it and not AfterUpdate appears in the
properties sheet - go figure :)

Insert the name of your TransactionDate field in the obvious place.

The lines starting with * are optional - they are to cater for your original
request which was to stay on the current record if the date changes. Here,
"ID" is the primary key field of your transactions table (TransactionID?).
It is not ProjectID. All the records will (must!) have the same ProjectID
because of the master/child link, so it's pointless doing a FindFirst as it
will always take you to the first record in the form!

However, if you have just changed the date from, say, 21-Nov to 22-Nov, the
record which had the focus before will now be excluded from the new date
filter, so no match will be found. Again, I think it's pointless, so I
suggest you omit the code.

You might also like to add a "Show All" button which removes the date
filter:
Me!fsubDailyBoxes.Form.FilterOn = False

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the options.

I think I just about have a modified option 2 in place already.

1. This form opens as a filter from the main Project form, so you don't
have
the option to see data for other stores from here.
2. I have a combo box that searches for the employees of the particular
store and shows all of their transactions in the subform.
3. I only need the calendar to filter the subform by the selected date.

Thanks a million for all of your efforts.
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

Unbound controls do not appear in the link fields wizard, but they can be
used (for master only, not child). I'm not sure if an unbound calendar
control can be used in LinkMasterFields (I've never tried) but if it
can't
then a textbox certainly can. You can set the ControlSource of a textbox
to
=[CalCtl1] and then use the textbox as your LinkMasterFields component.

The approach you should use here depends on your needs. You can either
have:

a) a subform showing ONLY the transactions for a given employee, project,
and date (all three must be selected)

or

b) what I call a "progressive filter" - all transactions are shown, but
when
an employee is selected from a combo box (or a project, or a date) the
list
is filtered accordingly. So you could show all transactions for a given
ProjectID, or for a given EmployeeID on a given date, or whatever.

The first option simply uses a subform with three paired fields as a
link.
This is simple, but I think it is not very flexible or user-friendly as
all
three criteria need to be specified.

The second option doesn't even require a subform - just a continuous
form -
and the AfterUpdate events for each of your three "selection controls"
builds a filter string and applies it to the form.

I'll give you some more details on the second option if you're interested
in
that approach.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi:

Sorry, I had a couple of requery statements that were causing
grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the
subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in the
calendar not a single thing happens. I was thinking that the date from
the
calendar would have to be criteria in the subform query, but the
Calendar
Control does not show up when I use the build button to add criteria
for
the
date field.

I guess I am expecting the transactions for the current employee to
filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form,
should
it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

What this means is that the value of lngProjectID in the current
record
of
your subform is Null. If this is the case, then surely it is
meaningless
to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store
(lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows
additions
and
you are on a new record).

Further, if you have just changed the date in the calendar then surely
the
record which was current on the subform before (corresponding to the
old
date) will no longer be included in the list for the newly selected
date,
so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my
confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am
getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the
transactions
an
employee made for the day at a particular store. Since an employee
can
work
at different branches, I have used lngProjectID and lngEmpID as my
link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make
finding
a
date easier for the end users. If there is a better way, then please
let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

As you have discovered, a Requery will always reset to the first
record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the
record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However, due
to
the
unhelpful response I received it looks like my questions were
answered.
My
questions were not answered so here I go again....... Thanks for
your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the
date
on
the
calendar of my main form as criteria.......my thought being that
when
the
date on the calendar changes then the date of the query changes
as
well.

I added a requery statement to the On Updated event of the
calendar,
but
the
subform will not change until I hit enter and then it also moves
to
the
first
record in the sub, I would like it to stay on the current record.

My code for the calendar event is simply:

Private Sub CalCtl1_Updated(Code As Integer)
Me!fsubDailyBoxes.Requery
End Sub

Any ideas??

--
Thanks for the brainwaves!

CJ
I blame the parents........
 
C

CJ

Ladies and Gentlemen,

The winner of the 2006 MVP of the year...........Graham Mandeno, Auckland
New Zealand!!!!!

Yeah Baby, absolutely brilliant! Exactly, exactly what I wanted to happen.

Thank you a million times for all of your effort and time.
Somebody needs to buy you a beer!!
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

OK, then you are currently linking the main and sub-forms using TWO fields -
ProjectID and EmpID, correct?

What you need to do is apply a filter to the subform when a date is selected
in the calendar:

Private Sub CalCtl1_AfterUpdate()
Dim sbf as Form
*Dim SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
*SavedID = Nz(sbf!ID, 0) ' take care of possible null
With sbf
.Filter = "[TransactionDate]=" _
& Format(CalCtl1.Value, "\#mm/dd/yyyy\#")
.FilterOn = True
End With
*With sbf.RecordsetClone
* .FindFirst "ID=" & SavedID
* If Not .NoMatch then sbf.Bookmark = .Bookmark
*End With
End Sub

Note that we are using the AfterUpdate event, not Updated. The Updated
event is not supported, even though it and not AfterUpdate appears in the
properties sheet - go figure :)

Insert the name of your TransactionDate field in the obvious place.

The lines starting with * are optional - they are to cater for your original
request which was to stay on the current record if the date changes. Here,
"ID" is the primary key field of your transactions table (TransactionID?).
It is not ProjectID. All the records will (must!) have the same ProjectID
because of the master/child link, so it's pointless doing a FindFirst as it
will always take you to the first record in the form!

However, if you have just changed the date from, say, 21-Nov to 22-Nov, the
record which had the focus before will now be excluded from the new date
filter, so no match will be found. Again, I think it's pointless, so I
suggest you omit the code.

You might also like to add a "Show All" button which removes the date
filter:
Me!fsubDailyBoxes.Form.FilterOn = False

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the options.

I think I just about have a modified option 2 in place already.

1. This form opens as a filter from the main Project form, so you don't
have
the option to see data for other stores from here.
2. I have a combo box that searches for the employees of the particular
store and shows all of their transactions in the subform.
3. I only need the calendar to filter the subform by the selected date.

Thanks a million for all of your efforts.
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

Unbound controls do not appear in the link fields wizard, but they can be
used (for master only, not child). I'm not sure if an unbound calendar
control can be used in LinkMasterFields (I've never tried) but if it
can't
then a textbox certainly can. You can set the ControlSource of a textbox
to
=[CalCtl1] and then use the textbox as your LinkMasterFields component.

The approach you should use here depends on your needs. You can either
have:

a) a subform showing ONLY the transactions for a given employee, project,
and date (all three must be selected)

or

b) what I call a "progressive filter" - all transactions are shown, but
when
an employee is selected from a combo box (or a project, or a date) the
list
is filtered accordingly. So you could show all transactions for a given
ProjectID, or for a given EmployeeID on a given date, or whatever.

The first option simply uses a subform with three paired fields as a
link.
This is simple, but I think it is not very flexible or user-friendly as
all
three criteria need to be specified.

The second option doesn't even require a subform - just a continuous
form -
and the AfterUpdate events for each of your three "selection controls"
builds a filter string and applies it to the form.

I'll give you some more details on the second option if you're interested
in
that approach.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi:

Sorry, I had a couple of requery statements that were causing
grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the
subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in the
calendar not a single thing happens. I was thinking that the date from
the
calendar would have to be criteria in the subform query, but the
Calendar
Control does not show up when I use the build button to add criteria
for
the
date field.

I guess I am expecting the transactions for the current employee to
filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form,
should
it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

What this means is that the value of lngProjectID in the current
record
of
your subform is Null. If this is the case, then surely it is
meaningless
to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store
(lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see *how*
lngProjectID could be null (unless perhaps your subform allows
additions
and
you are on a new record).

Further, if you have just changed the date in the calendar then surely
the
record which was current on the subform before (corresponding to the
old
date) will no longer be included in the list for the newly selected
date,
so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my
confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am
getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the
transactions
an
employee made for the day at a particular store. Since an employee
can
work
at different branches, I have used lngProjectID and lngEmpID as my
link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make
finding
a
date easier for the end users. If there is a better way, then please
let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

As you have discovered, a Requery will always reset to the first
record.
What you need to do is store the primary key value of the subform's
current
record before the requery, then do a FindFirst to reposition the
record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However, due
to
the
unhelpful response I received it looks like my questions were
answered.
My
questions were not answered so here I go again....... Thanks for
your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses the
date
on
the
calendar of my main form as criteria.......my thought being that
when
the
date on the calendar changes then the date of the query changes
as
well.

I added a requery statement to the On Updated event of the
calendar,
 
G

Graham Mandeno

Hi CJ

Thank you very much for your generous words - somewhat over-generous I
think! :)

I'm glad it's all working for you now.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Ladies and Gentlemen,

The winner of the 2006 MVP of the year...........Graham Mandeno, Auckland
New Zealand!!!!!

Yeah Baby, absolutely brilliant! Exactly, exactly what I wanted to happen.

Thank you a million times for all of your effort and time.
Somebody needs to buy you a beer!!
--
Thanks for the brainwaves!

CJ
I blame the parents........


Graham Mandeno said:
Hi CJ

OK, then you are currently linking the main and sub-forms using TWO
fields -
ProjectID and EmpID, correct?

What you need to do is apply a filter to the subform when a date is
selected
in the calendar:

Private Sub CalCtl1_AfterUpdate()
Dim sbf as Form
*Dim SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
*SavedID = Nz(sbf!ID, 0) ' take care of possible null
With sbf
.Filter = "[TransactionDate]=" _
& Format(CalCtl1.Value, "\#mm/dd/yyyy\#")
.FilterOn = True
End With
*With sbf.RecordsetClone
* .FindFirst "ID=" & SavedID
* If Not .NoMatch then sbf.Bookmark = .Bookmark
*End With
End Sub

Note that we are using the AfterUpdate event, not Updated. The Updated
event is not supported, even though it and not AfterUpdate appears in the
properties sheet - go figure :)

Insert the name of your TransactionDate field in the obvious place.

The lines starting with * are optional - they are to cater for your
original
request which was to stay on the current record if the date changes.
Here,
"ID" is the primary key field of your transactions table
(TransactionID?).
It is not ProjectID. All the records will (must!) have the same
ProjectID
because of the master/child link, so it's pointless doing a FindFirst as
it
will always take you to the first record in the form!

However, if you have just changed the date from, say, 21-Nov to 22-Nov,
the
record which had the focus before will now be excluded from the new date
filter, so no match will be found. Again, I think it's pointless, so I
suggest you omit the code.

You might also like to add a "Show All" button which removes the date
filter:
Me!fsubDailyBoxes.Form.FilterOn = False

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CJ said:
Hi Graham, thanks for the options.

I think I just about have a modified option 2 in place already.

1. This form opens as a filter from the main Project form, so you don't
have
the option to see data for other stores from here.
2. I have a combo box that searches for the employees of the particular
store and shows all of their transactions in the subform.
3. I only need the calendar to filter the subform by the selected date.

Thanks a million for all of your efforts.
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

Unbound controls do not appear in the link fields wizard, but they can
be
used (for master only, not child). I'm not sure if an unbound
calendar
control can be used in LinkMasterFields (I've never tried) but if it
can't
then a textbox certainly can. You can set the ControlSource of a
textbox
to
=[CalCtl1] and then use the textbox as your LinkMasterFields
component.

The approach you should use here depends on your needs. You can
either
have:

a) a subform showing ONLY the transactions for a given employee,
project,
and date (all three must be selected)

or

b) what I call a "progressive filter" - all transactions are shown,
but
when
an employee is selected from a combo box (or a project, or a date) the
list
is filtered accordingly. So you could show all transactions for a
given
ProjectID, or for a given EmployeeID on a given date, or whatever.

The first option simply uses a subform with three paired fields as a
link.
This is simple, but I think it is not very flexible or user-friendly
as
all
three criteria need to be specified.

The second option doesn't even require a subform - just a continuous
form -
and the AfterUpdate events for each of your three "selection controls"
builds a filter string and applies it to the form.

I'll give you some more details on the second option if you're
interested
in
that approach.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi:

Sorry, I had a couple of requery statements that were causing
grief.....they
are all gone now....no more error messages.

OK, the calendar is not bound to a field in the datasource for the
subform.
I just wanted to use it for locating transactions somehow.

At the moment, with your code in place, when I click on a date in
the
calendar not a single thing happens. I was thinking that the date
from
the
calendar would have to be criteria in the subform query, but the
Calendar
Control does not show up when I use the build button to add criteria
for
the
date field.

I guess I am expecting the transactions for the current employee to
filter
to the date that I am selecting with the calendar.

I also thought I should clarify, the calendar is on the main form,
should
it
be on the sub?

Does that help?
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

What this means is that the value of lngProjectID in the current
record
of
your subform is Null. If this is the case, then surely it is
meaningless
to
try to relocate it?

I'm further puzzled, because I understand your subform lists all
transactions for a given employee (lngEmpID) in a given store
(lngProjectID)
on a given day (CalCtl). If this is the case, then I cannot see
*how*
lngProjectID could be null (unless perhaps your subform allows
additions
and
you are on a new record).

Further, if you have just changed the date in the calendar then
surely
the
record which was current on the subform before (corresponding to
the
old
date) will no longer be included in the list for the newly selected
date,
so
trying to locate the old current record seems pointless.

There is something I'm missing here - could you please dispel my
confusion?
:)
--
Thanks,

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Graham, thanks for the response.

I added your code to the Click event of the calendar but I am
getting
"Invalid use of null"

A few details that might help you out.

1. The subform is continuous, it basically show all of the
transactions
an
employee made for the day at a particular store. Since an
employee
can
work
at different branches, I have used lngProjectID and lngEmpID as
my
link
fields to the main Store form.
2. The calendar is unbound. I was hoping to use it just to make
finding
a
date easier for the end users. If there is a better way, then
please
let
me
know.

Here is the code that I have in place now.
Private Sub CalCtl1_Click()

Dim sbf As Form, SavedID As Long

Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!lngProjectID <This is the break point>
sbf.Requery
With sbf.RecordsetClone
.FindFirst "lngProjectID=" & SavedID
If Not .NoMatch Then sbf.Bookmark = .Bookmark
End With

End Sub
--
Thanks for the brainwaves!

CJ
I blame the parents........


:

Hi CJ

As you have discovered, a Requery will always reset to the first
record.
What you need to do is store the primary key value of the
subform's
current
record before the requery, then do a FindFirst to reposition the
record
after the requery. Something like this:

Dim sbf as Form, SavedID as Long
Set sbf = Me!fsubDailyBoxes.Form
SavedID = sbf!ID
sbf.Requery
With sbf.RecordsetClone
.FindFirst "ID=" & SavedID
If not .NoMatch then sbf.Bookmark = .Bookmark
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

This was originally posted yesterday, November 16. However,
due
to
the
unhelpful response I received it looks like my questions were
answered.
My
questions were not answered so here I go again....... Thanks
for
your
patience.

Hi groupies.

I have a subform tied to a query. The date of the query uses
the
date
on
the
calendar of my main form as criteria.......my thought being
that
when
the
date on the calendar changes then the date of the query
changes
as
well.

I added a requery statement to the On Updated event of the
calendar,
 

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