473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Combining Enter Perimeter Values for a Button

I have a button in a form which runs four queries after a user presses it. Two of the queries ask for a start date to be entered so that it can look up specific records. The start dates required for both quieres will always be the same, but for the queries to correctly search the records, the start state must be entered; thus the user gets 2 consective prompts when he or she presses the button. Is there a way to combine the two prompts so the user doesn't have to enter the same thing twice in a row? Thanks in advance.
Aug 11 '10 #1
18 2435
ADezii
8,834 Expert 8TB
Have the User enter the Start Date on the Form and eliminate the Prompts altogether. In the Queries, set the Criteria of the [StartDate] Field to:
Expand|Select|Wrap|Line Numbers
  1. Forms![<Form Name>]![StartDate]
Aug 11 '10 #2
That sounds like a good idea. I have a lot of other buttons on the form and I don't want to change the interface integrity of it by putting in boxes where you can directly enter text into. Is there a way to combine the 2 search prompts any other way?
Aug 12 '10 #3
NeoPa
32,556 Expert Mod 16PB
Steve,
  1. It is possible. It is not recommended, but it is possible using InputBox().
  2. The most user friendly option is certainly to use a form, even if you have to open a new one specially. When using InputBox() it is necessary to modify the SQL used. This can involve creating temporary QueryDefs just to run the query. Messy!
  3. I notice you are using a different and new user name. While this is acceptable simply to contact an administrator to ask for help resolving your issue, we do not allow users to run multiple accounts in the normal course of events.

    Please PM me any difficulties you may have and we'll see what can be done to get you back using your proper account.

-NeoPa (Admin).
Aug 12 '10 #4
ADezii
8,834 Expert 8TB
NeoPa offers a viable, and unique, alternative in Post #4, and if you are interested in implementing it, I'll be happy to point you in the right direction. I would, however, need the SQL for the two Queries posted. My approach would be to directly modify the SQL Property of the two Queries based on the Value returned by the InputBox() Function, then execute them. The only Prompt would be that of InputBox() itself. With minimum Validation, this approach should work quite well.
Aug 12 '10 #5
NeoPa
32,556 Expert Mod 16PB
I'm not sure it's a responsible approach simply to fiddle with existing QueryDefs ADezii, or were you referring to executing the resultant SQL strings?

If the former, then see my comment in post #4 about using Temp QueryDefs. This would be a safer approach as you cannot know what else these QueryDefs are used for and fiddling with their design for one job is unlikely to be a safe approach.

If, on the other hand, executing the SQL strings is intended, then you need to know that only action queries can be executed in that way.
Aug 12 '10 #6
ADezii
8,834 Expert 8TB
Depending on the specific circumstances, my original concept was to:
  1. Capture the SQL from the Query
  2. Modify the Query's SQL directly for specific Criteria
  3. Open the Query
  4. Restore Original SQL
    Expand|Select|Wrap|Line Numbers
    1. Dim strSQL As String
    2. Dim strSQL2 As String
    3.  
    4. 'Capture Original SQL
    5. strSQL = CurrentDb.QueryDefs("qryEmployees").SQL
    6.  
    7. 'New SQL Statement based on Criteria
    8. strSQL2 = "SELECT * FROM Employees WHERE [TitleOfCourtesy] = '" & "Mr." & "';"
    9.  
    10. CurrentDb.QueryDefs("qryEmployees").SQL = strSQL2
    11.  
    12. DoCmd.OpenQuery "qryEmployees", acViewNormal, acReadOnly
    13.  
    14. 'Restore Original SQL
    15. CurrentDb.QueryDefs("qryEmployees").SQL = strSQL
  5. After careful consideration, I guess a Temporary QueryDef may be the way to go.
Aug 12 '10 #7
NeoPa
32,556 Expert Mod 16PB
It's probably safer as :
  1. The user may not have access rights to update the query.
  2. Another user may attempt to use the query during the time it is in a modified state.

Multi-user can be a bitch huh :D
Aug 12 '10 #8
ADezii
8,834 Expert 8TB
Both points well stated and accepted. A Temporary QueryDef it is!
Aug 12 '10 #9
How do you see the SQL code for queries you make in design view? I know you can go into VBA mode with the code button if you are looking at forms, but the same button is grayed out when you are looking at queries. Where would you put the inputbox commands in?
Aug 13 '10 #10
ADezii
8,834 Expert 8TB
First things first:
  1. In the Database Window
  2. Click the Queries Tab
  3. Select a Query
  4. Click Design
  5. View ===> SQL
Aug 13 '10 #11
NeoPa
32,556 Expert Mod 16PB
From Design View select View / SQL View.

The InputBox() call, if used, would be in the VBA only.
Aug 13 '10 #12
ADezii
8,834 Expert 8TB
Hello NeoPa, just a errant thought that came to me while I was getting a shower (scary thought, I know!). Temporary QueryDefs are a great little tool, but there are only two things that you can do with them, since they have no Visual Component:
  1. Execute them if they are Action Queries (don't think that this is the case here)
  2. For Non-Action Queries, assign their Output to a Recordset.
Assuming we are dealing with Non-Action Queries, this would leave us high and dry, since I'm assuming that the OP is looking for some sort of visual display.
Aug 13 '10 #13
NeoPa
32,556 Expert Mod 16PB
Good point ADezii. That takes me back (I dealt with all this a long while back now).

I have my own Temp QueryDef objects that I manage and delete when done with. They're actually named so not properly Temporary, but I just use them that way. I was referring to these and forgetting that wouldn't make much sense.

I'd be happy to post my routine for creating them, but it does have a few dependent procedures so probably wouldn't run for you. It might give you a clue as to the logic though if you feel that would help.

If you're really interested I'll look at paring it down to work in a more portable environment, but I'm not keen to unless there's real interest.

Fundamentally, for a situation such as this, it copies the QueryDef that is required and modifies the SQL. This new object is deleted when it's finished with.

I believe this sort of thing can more easily be accomplished in private FE databases (Those where each user has their own local copy).
Aug 13 '10 #14
ADezii
8,834 Expert 8TB
I'm actually now leaning toward creating an Actual Query, dynamically assigning the SQL for it, Open it for visual display so the User can actually see the results, then at some point Delete the Object. This should eliminate the potential Multi-User problem as well as access rights. What is your slant on this approach?
Aug 13 '10 #15
NeoPa
32,556 Expert Mod 16PB
That's pretty well exactly what I've done in my databases ADezii (See post #14). If you're interested in seeing any of my code just let me know.
Aug 13 '10 #16
ADezii
8,834 Expert 8TB
@Stevstan - I'm getting ready to go on Vacation, but before I did, there is something that I wanted to do in an attempt to gain some closure as far as this Thread goes. I created a Demo Database, based on the Orders Table of the Sample Northwind Database, that illustrates virtually all the points discussed in this Thread, plus a few others. Please keep in mind NeoPa's major contribution to this Thread also. The code will demonstrate the following:
  1. Use of the InputBox$() Function to retrieve what will be a Parameter (DATE) to be used in Multiple Queries.
  2. Validation on that Value obtained from InputBox$ to make sure that a Value was entered, the Value is an actual Date, and the Value falls within a specified Range.
  3. Dynamic generation of SQL Statements using that Value retrieved from InputBox$.
  4. Creation of 2 Queries using that Value in an opposing manner, namely: >= and <.
  5. Opening both Queries and Tiling then Horizontally.
  6. How to DELETE these Temporary Queries at some appropriate point.
  7. The basic Code Segment follows:
    Expand|Select|Wrap|Line Numbers
    1. Dim strDate As String
    2. Dim qdf As DAO.QueryDef
    3. Dim qdf_1 As DAO.QueryDef
    4. Dim qdf_2 As DAO.QueryDef
    5. Dim strSQL_1 As String
    6. Dim strSQL_2 As String
    7.  
    8. strDate = InputBox$("Enter a Valid Date in the Format mm/dd/yyyy:", "Date Entry")
    9.  
    10. 'Let's perform some Validations on the Return Value of InputBox$()
    11. If strDate = "" Then    'No Value entered, then OK or User clicked on Cancel
    12.   Exit Sub
    13. ElseIf Not IsDate(strDate) Then     'Must be a Valid Date, not some erroneous Value
    14.   MsgBox "[" & strDate & "] is not a Valid Date" & vbCrLf & vbCrLf & _
    15.          "You must enter a Valid Date in the Format mm/dd/yyyy", vbExclamation, "Invalid Date"
    16.             Exit Sub
    17. ElseIf CDate(strDate) < #8/4/1994# Or CDate(strDate) > #6/5/1996# Then    '>=8/4/1994 And <= 6/5/1996
    18.   MsgBox "The Date entered must be between 8/4/1994 and 6/5/1996", vbExclamation, "Invalid Date"
    19.     Exit Sub
    20. End If
    21.  
    22. 'If you get here, the User entered a Valid Date within the Range 8/4/1994 to 6/5/1996
    23. strSQL_1 = "SELECT * FROM Orders WHERE [OrderDate] >= #" & CDate(strDate) & "#;"
    24. strSQL_2 = "SELECT * FROM Orders WHERE [OrderDate] < #" & CDate(strDate) & "#;"
    25.  
    26. With CurrentDb
    27.   Set qdf_1 = .CreateQueryDef("qryOrders_1", strSQL_1)
    28.   Set qdf_2 = .CreateQueryDef("qryOrders_2", strSQL_2)
    29. End With
    30.  
    31. DoCmd.Minimize      'Minimize Main Form
    32.  
    33. 'Open both Queries
    34. DoCmd.OpenQuery "qryOrders_1", acViewNormal, acReadOnly
    35. DoCmd.OpenQuery "qryOrders_2", acViewNormal, acReadOnly
    36.  
    37. 'Tile all Windows Horizontally
    38. DoCmd.RunCommand acCmdTileHorizontally
  8. At some point, you would want to DELETE these Temporary Queries:
    Expand|Select|Wrap|Line Numbers
    1. On Error Resume Next
    2. 'You should DELETE the Temporarily created Queries at some point,
    3. 'that can only be determined by you
    4. CurrentDb.QueryDefs.Delete "qryOrders_1"
    5. CurrentDb.QueryDefs.Delete "qryOrders_2"
  9. I've posted the code for anyone who does not wish to Download the Attachment, but I would highly advise you (Stevstan) to download the Attachment in order to get a clear picture of exactly what is going on.
Attached Files
File Type: zip InputBox.zip (63.2 KB, 93 views)
Aug 14 '10 #17
Thanks for this code Adezil. I tried incorporating it into my queries, but can't get it to run smoothly. Here is my VBA code for the two queries that ask for the user input before I added any of the code you provided.


Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT rpt_vwCaseData.CaseID, rpt_vwCaseData.Date_ST, rpt_vwCaseData.TeamID_PrimaryAgent_ST, rpt_vwCaseData.UserID_CreatedBy_ST, rpt_vwCaseData.CaseTypeName, rpt_vwCaseData.sIssueName, rpt_vwCaseData.DateClosed, rpt_vwCaseData.sCustID INTO IRSJake
  2. FROM rpt_vwCaseData
  3. WHERE (((rpt_vwCaseData.Date_ST) Between [Queries]![< QS_AllcasesIRS_STEP1>]![enter first day of  reporting month] And [enter first day of following month]) AND ((rpt_vwCaseData.TeamID_PrimaryAgent_ST)=40));


Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT rpt_vwCaseData.CaseID, rpt_vwCaseData.Date_ST, rpt_vwCaseData.TeamID_PrimaryAgent_ST INTO AllCasesTeam40
  2. FROM rpt_vwCaseData
  3. WHERE (((rpt_vwCaseData.Date_ST) Between (Now()-395) And [enter first day of  reporting month]) AND ((rpt_vwCaseData.TeamID_PrimaryAgent_ST)=40));



Any suggestions on how to integrate the code you provided into these?
Aug 18 '10 #18
ADezii
8,834 Expert 8TB
At this point, I feel as though I would ned to see the Database. Any hance of uploading it, or a subset of it, pointing the specifics along the way?
Aug 21 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alan Zhong | last post by:
i am trying to similate an "ENTER" as a key to switch focus in a sequence of text inputs. i don't want to use "event.keyCode" since i want to do additional testing before i decide which text input...
1
by: serge | last post by:
How can i enter Default Values of " " to all the columns of type character of all the tables (excluding system tables) and Default Values of 0 of all columns of type numbers. Excluding all primary...
2
by: RBohannon | last post by:
I have a report with most fields populated by a query. However, some of the fields are variable in such a way that their values cannot be queried from a table. At present the values for these...
2
by: Phillip Kennedy | last post by:
Hi, HELP!!!! we are having a problem where we have a web page with a number of buttons and form fields, unfortunately whenevr we hit the enter key in a form field it is envokingthe 1st button,...
3
by: David Lozzi | last post by:
Howdy, I'm using asp.net 2.0 and am trying to get one text box on the page, after the user presses enter, to "click" a specific button. I copied the javascript I used for a .net 1.1 web app I...
1
by: CPP amateur | last post by:
Default arguments are those arguments that are substituted for the missing arguments in the function call. Is it possible to enter default values, instead of providing them in the function prototype...
1
by: n3ox3ro | last post by:
If im using an "enter parameter values" box in a query to find information in a table and if you type in a value that doesnt exist how do you stop if from displaying a blank screen on your form??
1
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
0
by: gimme_this_gimme_that | last post by:
I have a JSP that renders a XHTML formatted page. The user clicks a button (not a submit) that calls a validate JavaScript function that submits the form. The user clicks and goes to a...
1
by: rose1 | last post by:
In C#.net (windows Application) enter the values directly in MSFlegrid in Runtime using C#.net
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.