Multiple Forms with a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In an access database, I have a start menu with buttons on it. In the
problem that I am working on, if the user presses button A, I am trying to
make it so that a pop-up box will appear with two blank fields for a Begin
Date and an End Date. Once the user has put values into these fields, and
presses the close (or enter) button, I want those values to be used in
running a make-table query via a macro. Then, the results of the make table
query are to be displayed on a separate form which can not be edited. I have
everything working so far except for the part where the pop-up box holds the
begin and end dates. I am desperate. Please help!

Here is what I have so far:

Private Sub Command299_Click()
On Error GoTo Err_Command299_Click

Dim stDocName As String
Dim stLinkCriteria As String

DoCmd.OpenForm "frm_QOSDateRange"

DoCmd.OpenQuery "qry_MP2_QOS_ISSREC_Data_tbl", , acReadOnly

stDocName = "frm_MP2_QOS_ISSREC_Data_JP_Linked_To_Table"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command299_Click:
Exit Sub

Err_Command299_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command299_Click
End Sub
 
How are you sending the dates to the query? I would do this:
Private Sub Command299_Click()
On Error GoTo Err_Command299_Click

DoCmd.OpenForm "frm_QOSDateRange"

Exit_Command299_Click:
Exit Sub

Err_Command299_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command299_Click
End Sub

Then on the date range form, put a button that hides the form, and runs the
query and then opens the last form, then finally closes the date form.

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String
Dim stLinkCriteria As String

If not isnull(Me![StartDate]) and not isnull(Me![EndDate])
Me.visible = false
DoCmd.OpenQuery "qry_MP2_QOS_ISSREC_Data_tbl", , acReadOnly

stDocName = "frm_MP2_QOS_ISSREC_Data_JP_Linked_To_Table"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Docmd.closeform me.name
else
msgbox("Please enter the date range")
end if

Exit_Command299_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command1_Click
End Sub

Then in your query make sure the criteria for the date is:
Between forms![frm_QOSDateRange]![StartDate] and
Forms![frm_QOSDateRange]![endDate]

You may also want to add a cancel button to your date range form to close it
without running the query and opening the form.
 
It won't do the two input fields simultaneously, but a parameter query pulled
up by a form will do what you describe. Put "Between [Beginning Date:] and
[End Date:]" in the Criteria field of your query and Access will prompt for
the dates, one at a time, whenever the query is run.
 
This will work also, I just like using a form to enter the parameters so you
can control the input better.
 

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

Similar Threads


Back
Top