Linking Form to query

T

Tommy2326

Ive got a form that uses a calendar to select a date range. The date range
is displayed in txtStartDate and txtEndDate. I want to use these two dates
to open a form showing data between these dates. how do I link the the text
boxes to the form. The form is opened using btnMachineDowntime. The form is
called Machine Downtime - Select Date and is based on a query called Machine
Downtime - Select Date.

Thanks for the help

Tommy
 
C

Carl Rapson

Tommy2326 said:
Ive got a form that uses a calendar to select a date range. The date
range
is displayed in txtStartDate and txtEndDate. I want to use these two
dates
to open a form showing data between these dates. how do I link the the
text
boxes to the form. The form is opened using btnMachineDowntime. The form
is
called Machine Downtime - Select Date and is based on a query called
Machine
Downtime - Select Date.

Thanks for the help

Tommy

In the OpenForm call, pass the date range in the WhereCondition parameter:

DoCmd.OpenForm "", , , "[my date field] BETWEEN #" & txtStartDate & "# AND
#" & txtEndDate & "#"

This has the same effect as adding a WHERE clause to the query that the form
is based on.


Carl Rapson
 
T

Tommy2326

In the OpenForm call, pass the date range in the WhereCondition parameter:
DoCmd.OpenForm "", , , "[my date field] BETWEEN #" & txtStartDate & "# AND
#" & txtEndDate & "#"

This has the same effect as adding a WHERE clause to the query that the form
is based on.


Carl Rapson

I can't get the above to work, not sure exactly where to put it. I tried
putting it in the command button 'btnMachineDowntime' after, and in, the line:

DoCmd.Openreport stdocName, acPreview

This is the standard code you get from the command buttons wizard. I also
put it in the event 'Private Sub Form_Open(Cancel As Integer)' this is'nt
used for anything else just tried putting your code in there. I can get the
report to open properly from the form, you have to type in the dates after
you press 'btnMachineDowntime' but would prefer if I could get this from the
two dates entered through the calendar. The calendar I'm using is Stephen
Lebans Month Calendar version 9.6

Tommy
 
C

Carl Rapson

Tommy2326 said:
In the OpenForm call, pass the date range in the WhereCondition
parameter:

DoCmd.OpenForm "", , , "[my date field] BETWEEN #" & txtStartDate & "#
AND
#" & txtEndDate & "#"

This has the same effect as adding a WHERE clause to the query that the
form
is based on.


Carl Rapson

I can't get the above to work, not sure exactly where to put it. I tried
putting it in the command button 'btnMachineDowntime' after, and in, the
line:

DoCmd.Openreport stdocName, acPreview

This is the standard code you get from the command buttons wizard. I also
put it in the event 'Private Sub Form_Open(Cancel As Integer)' this is'nt
used for anything else just tried putting your code in there. I can get
the
report to open properly from the form, you have to type in the dates after
you press 'btnMachineDowntime' but would prefer if I could get this from
the
two dates entered through the calendar. The calendar I'm using is Stephen
Lebans Month Calendar version 9.6

Tommy
 
C

Carl Rapson

Tommy2326 said:
In the OpenForm call, pass the date range in the WhereCondition
parameter:

DoCmd.OpenForm "", , , "[my date field] BETWEEN #" & txtStartDate & "#
AND
#" & txtEndDate & "#"

This has the same effect as adding a WHERE clause to the query that the
form
is based on.


Carl Rapson

I can't get the above to work, not sure exactly where to put it. I tried
putting it in the command button 'btnMachineDowntime' after, and in, the
line:

DoCmd.Openreport stdocName, acPreview

This is the standard code you get from the command buttons wizard. I also
put it in the event 'Private Sub Form_Open(Cancel As Integer)' this is'nt
used for anything else just tried putting your code in there. I can get
the
report to open properly from the form, you have to type in the dates after
you press 'btnMachineDowntime' but would prefer if I could get this from
the
two dates entered through the calendar. The calendar I'm using is Stephen
Lebans Month Calendar version 9.6

Tommy

The code should be in the command button's AfterUpdate event, not the form's
Open event. It sounds like you have the date parameters included in your
query, and so it's prompting you for them when the report opens and the
query runs. Remove any WHERE clause from the query the report is based on,
and try this code instead in the button's AfterUpdate event:

DoCmd.OpenForm "stdocName", acPreview, , "[my date field name] BETWEEN #" &
txtStartDate & "# AND #" & txtEndDate & "#"

Carl Rapson
 

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