473,386 Members | 1,766 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,386 software developers and data experts.

Using a form to input information for a report

283 100+
Hi everyone,

Well i have been playing with this for a few days and so far im getting no where. What I have is a form I created that you input a little data in order to pull a report. I have a report and query that already work great so im trying to intergrate it in to the report. Right now its set up where if you open the report you have to type in a date range, location name, and shift number what i want to do is make it so I can type that information in to a form i have set up and the query will go off of the information you type in the form instead of the little pop up boxes asking you to type it in.

One thing I did was for the shift number I set up 5 toggle buttons that would represent numbers 1 - 5 so when I press a toggle button i want that to register to the query as shift number, then you type in a location name and date range in text boxes.

I found a website that seems to have the information im looking for but been playing with it for a couple days now and im not sure what im doing wrong.

Any help would be great thanks

here is the site if found,
http://office.microsoft.com/en-us/access/HP051874111033.aspx
May 19 '10 #1
25 2629
TheSmileyCoder
2,322 Expert Mod 2GB
You can pass the variables in the openarg argument when opening the report(And then process it in within the report), you can base the reports query criteria directly upon the controls in the form (the form must then stay open) or you can use the form to setup a filter string, and pass that filter string to the report when opening it.

In most cases I would go with using the filter string.
Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria as String
  2. 'Example of input checking, repeat for location and shift
  3. If Me.txtDateRange & ""="" Then
  4.   Msgbox "You must enter a date",VbOkOnly+vbExclamation
  5.   Exit Sub
  6. End If
  7.  
  8. strCriteria="ID_Location=" & Me.ComboBox_Location & " AND dtDate=#" & Me.txtDate & "# AND ID_Shift=" & Me.ComboBox_Shift
  9. Docmd.OpenReport "MyReport",acPreview,,strCriteria
  10.  
This code is assuming you are using a combobox for selecting the location and shift (And you should never use a normal textbox for entering location!)
May 19 '10 #2
slenish
283 100+
Hi TSO,

Nice example!! Seems to be exactly what I was looking for. Just having one problem. Not sure where to put this. You said to use the form to set up a filter string but where would i put this? In the form commands? Or in the print command button? Or should I put it in a macro and then reference the macro when the button is pressed?

Thanks again!
May 19 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
I would put it in the print command button. If you want the report to print directly, without previewing, jsut replace acPreview with acNormal.
I myself have completely stopped using macros, as I seem to find it confusing to use part VBA code and part macros. Besides I find VBA to be 1000x more powerfull.
May 19 '10 #4
slenish
283 100+
Hi TSO,

Thanks for writing back so quickly. Ok i plugged in the code and adjusted it but i am getting either a syntax error, type mismatch error, or a debug error. I put the code in to the on click event of the command button.

here is what I have,
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "Agency = " & Me.Agency & " AND Date = me.BeginningDate #" & Me.EndingDate & #"  AND Shift =" & Me.Toggle6
  2.  
Not sure where the problem is. Im thinking it might be with the date. Just wondering do i need to break the date field in to two boxes on the query for this to work with a start and end date? right now i have it set up as a where expression and it works when you just type it in the little pop up boxes.

I have another question that i just thought of. On my report i have a date field set up with
Expand|Select|Wrap|Line Numbers
  1. =[Enter Start Date] & " - " & [Enter End Date]
  2.  
should i change that to look at the form as well something like
Expand|Select|Wrap|Line Numbers
  1. [Forms]![Form1]![BeginningDate]![EndingDate] 
  2.  
Just wondering if i should change part of the report and/or the query such as the criteria so that it also looks at the boxes on the form? Or should the code in the onClick command do everything?


Yeah i am not much of a macro user myself. I feel like they take to long to reference most of the time. From my experiences so far if you have VBA code right in the properties it seems to work a lot better. :)

Thanks again for helping me with this.
May 19 '10 #5
slenish
283 100+
...........
May 19 '10 #6
NeoPa
32,556 Expert Mod 16PB
Slenish,

You need to understand that a thread is not a general conversation. You need to post separate questions in separate threads otherwise everything gets into an unholy mess.
May 19 '10 #7
NeoPa
32,556 Expert Mod 16PB
slenish:
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "Agency = " & Me.Agency & " AND Date = me.BeginningDate #" & Me.EndingDate & #"  AND Shift =" & Me.Toggle6
  2.  
Not sure where the problem is.
There are so many it's hard to list them all. I suggest you look at strCriteria after you've set it and see what it contains. This will give you a much better understanding of where the problems are. See below for more on this.
One of the most popular (frequently occurring rather than best liked) problems we get is with SQL strings being manipulated in VBA code.

The reason this is so difficult is that all the work is being done at a level of redirection. What I mean by this is that the coder is never working directly with the SQL itself, but rather with code which in turn, is relied on to produce the SQL that they are envisaging is required. It's rather similar to the problems coders have historically had dealing with pointers.

Anyway, a technique I often suggest to coders struggling with this (at any level. This happens to experienced coders too.) is to use either the MsgBox() function, or Debug.Print into the Immediate Pane of the debugger window, to display the value of the SQL in the string before using it (That's assuming you're not good with debugging generally. Personally I would trace to the line, then display the value prior to allowing execution of the string - See Debugging in VBA). It's really much easier to appreciate what a SQL string is meant to do, and where there may be problems, when you can see it in its entirety, and in its true form, rather than as the code is about to create it.
May 19 '10 #8
slenish
283 100+
Hi NeoPa,

Sorry I was not meaning for my post to run on as a conversation also both posts go with the same original question just trying to figure out if there is more that I need to do from other angles than just typing in some code for the on click command.

Thanks for the info about using the Debugging. I will plug that in and see if it can show me anything more that im not seeing.

Thanks again
May 19 '10 #9
NeoPa
32,556 Expert Mod 16PB
To be consistent it would need to be more like :
Expand|Select|Wrap|Line Numbers
  1. =[Forms]![Form1]![BeginningDate] & ' - ' & [Forms]![Form1]![EndingDate]
May 20 '10 #10
NeoPa
32,556 Expert Mod 16PB
slenish: sorry both posts go with the same question i can just put them together
No.

That is neither correct nor acceptable. These are clearly separate questions and if we find such abuse of threads in future they will be edited and you will pick up a site infraction. I hope I'm being clear.

If you have any confusion about what is and is not acceptable then please read the site rules (FAQ: Posting Guidelines). These can be found from the site FAQ which is available on every page.

-Administrator.
May 20 '10 #11
NeoPa
32,556 Expert Mod 16PB
I can see that you have edited your original response to make it clearer. As a general rule we are a little flexible with this. I'm not sure this really falls into that category, but we'll let it slide for now. Please be careful in future though - now you understand how much of a problem this can be and how serious we are about enforcing it.
May 20 '10 #12
slenish
283 100+
Well i have been playing with the code more and trying to get this to work. Now I have it to accept the information from the form but on my report all of the info comes out in errors.

What I did was I put a few lines of code in to the query critera to make it look at the form and the boxes with the user input. Its seems to understand that something has been typed in but there is no output except the date for some reason.

here is what i have in the date, agency, shift critera
Expand|Select|Wrap|Line Numbers
  1. [Forms]![ReportMenu]![BeginningDate] & '-' & [Forms]![ReportMenu]![EndingDate]
  2.  
  3. [Forms]![ReportMenu]![Agency]
  4.  
  5. [Forms]![ReportMenu]![Toggle'*']
  6.  
I also still have what TSO said to use in the form in the on button click along with on the report itself where the date field is i used the same code (as above) which could be why that one is working.

Also I will stive to be more politically correct in my posts going forward

Thanks
May 20 '10 #13
NeoPa
32,556 Expert Mod 16PB
Here are my guesses as to what you're really looking for in the three posted examples. I hope this proves fruitful.
  1. Expand|Select|Wrap|Line Numbers
    1. Between [Forms]![ReportMenu]![BeginningDate] And [Forms]![ReportMenu]![EndingDate]
  2. Expand|Select|Wrap|Line Numbers
    1. [Forms]![ReportMenu]![Agency]
  3. Expand|Select|Wrap|Line Numbers
    1. Like [Forms]![ReportMenu]![Toggle] & '*'
Let me know if any of these help.
May 20 '10 #14
slenish
283 100+
@NeoPa
Hi NeoPa,

I have to say you are the man! Worked like a charm. My only problem now is trying to get the toggle buttons to equal different values for the shift. I set up one like this
Expand|Select|Wrap|Line Numbers
  1. dim value as string
  2. value = 1
  3. if toggle = true then 
  4. toggle = value
  5. else 
  6. toggle = false
  7. end if
  8.  
not sure if i did that right or not because it puts a number one in the box for shift that it understand the value but instead of pulling just the information for shift 1 it pulls all shifts which I want for a different toggle button. Any ideas?

Thanks again for helping me with this
May 21 '10 #15
NeoPa
32,556 Expert Mod 16PB
I'm pleased that helped :)

Unfortunately I read the rest a couple of times but could make no sense of it. I have no idea what you're asking.
May 21 '10 #16
slenish
283 100+
@NeoPa
Ah sorry i might not has said that very clear.

Let me try again :)

What I have are 5 toggle switches. I want each one to represent a number value so what will happen is if you press toggle1 it will = 1 so when I hit the run report button it knows to pull the information for shift 1 if I hit toggle button 2 it will = 2 and pull the information for shift 2, and so on. The last toggle button will = 0 for all shift numbers and pull the information for all of them together. Any idea how i can get that to work right? I have it working for 1 toggle button but the way i did it is definatly not the best way.

I set up one button to have a value of 1 then I set the query for shift to look at that one toggle button then I set the report to also look at that toggle button. Just trying to figure out how can i set it so the query and the report will just look at any toggle button I press and not only 1.

Hope this is a little clearer

*UpDate*

Ok I figured out how to get this to work, but im still having some trouble. What I did was in the query critera i used the OR operator and then typed the next toggle button. Plus in the onClick command of each toggle button I set them to a value such as 1, 2, 3.

example
Expand|Select|Wrap|Line Numbers
  1. [forms]![ReportMenu]![Toggle6] Or [Forms]![ReportMenu]![Toggle7] 
  2.  
but the problem im getting now is trying to make it pull all the information. Before if I left the Shift critera blank and the Agency name blank it would pull all of the information. Now when I try to set a Toggle buttons value to "" and leave the Agency field blank i just get errors.

Any ideas?
May 21 '10 #17
OldBirdman
675 512MB
Toggle Buttons, like Radio Buttons, can be items in a Frame. Each button will have a value that is assigned to the frame when the button is pressed. The frame will also set all the other buttons to "False", so only one can be pressed at a time. The Frame can be made borderless, flat, and transparent if you do not want it to show. The captions on the buttons can be descriptive: Day, Swing, Graveyard, All, ...
If the "All Shifts" button is pressed, then the shift element is not used in the SQL statement.
May 21 '10 #18
NeoPa
32,556 Expert Mod 16PB
I suspect OB's answer is what you need here Slenish. Let us know how you get on :)
May 23 '10 #19
slenish
283 100+
Thank you OldBirdman and NeoPa,

Well im still having trouble with this. I got one problem fixed which was getting my agency drop down to accept a blank value and it would pull all the information but im still having a problem with the "All Shifts" toggle button.

Here is what i tried. I tried to set the All Shifts button to have a value of "*". I also set up an effect were if you press one toggle button all of the other toggle buttons disapear and other information pops up, but if you press the toggle button again it should reset the form and all the buttons come back. For some reason with the value set to "*" it will not reset the form but as soon as i put a number value in for the button it works fine. I thought maybe it I set the toggle value to "*" then it would pull all information for all shifts which seems to work with the Agency. I would just make adjustments in the query. So im still having touble with this. Not sure how to set the SQL statement to not be used if the button is pressed. Any further examples would be great.

appreaciate the help!!
May 29 '10 #20
NeoPa
32,556 Expert Mod 16PB
I've read this a number of times and still find nothing I can work with.

If you're asking a question please give enough context for the question to make sense in an Access environment. Telling me you're using "*" doesn't give me any understanding unless I have some context. At this stage of the thread I don't want to have to reread all the other posts to work out your meaning. It is your responsibility to post a question that is understandable. Not ours to research so much that we can turn what you say into something that makes sense.
Jun 3 '10 #21
slenish
283 100+
@NeoPa
Hi NeoPa,

Wanted to let you know I finally got this to work earlier today. I found out with toggle buttons in order for them to work right you have to set them as a number value. So what I did was set the All Shifts Toggle to equal a value of 5. Then I created a new column on my table for employee names that was called all shifts that held the value 5 so when the button was clicked it would look at the table for the number 5 and know to pull all the records. Which was really cool. Took me a while to get it but yeah i did it! :D
Jun 9 '10 #22
NeoPa
32,556 Expert Mod 16PB
Clearly communicating via a forum can be difficult at times, but nevertheless I'm pleased you managed to find your solution. It's often more gratifying that way anyway, as I'm sure you know :)
Jun 9 '10 #23
slenish
283 100+
Yeah it is hard to always communicate exactly what you are trying to do on forums with out seeing the actual program. It is a nice feeling when you figure it out on your own, frustrating during the process but a relief in the end. :) thanks again for the support
Jun 9 '10 #24
ADezii
8,834 Expert 8TB
@slenish
After making certain assumptions on the Form and Control Names, the SQL would look similar to:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.TheDate, tblTest.Location, tblTest.[Shift Number]
  2. FROM tblTest
  3. WHERE tblTest.TheDate Between [Forms]![Form1]![txtStartDate] And [Forms]![Form1]![txtEndDate] 
  4. AND tblTest.Location=[Forms]![Form1]![txtLocation]
  5. AND tblTest.[Shift Number]=[Forms]![Form1]![txtShiftNumber];
Jun 9 '10 #25
OldBirdman
675 512MB
I don't think the last code addresses the "All Shifts" issue. Perhaps better is:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. If [Forms]![Form1]![txtShiftNumber] = 5 then
  3.   strSQL = ";"
  4. Else
  5.   strSQL = " AND tblTest.[Shift Number]=[Forms]![Form1]![txtShiftNumber];"
  6. End If
  7. strSQL = "SELECT tblTest.TheDate, tblTest.Location, tblTest.[Shift Number] " & _
  8. "FROM tblTest " & _
  9. "WHERE tblTest.TheDate Between [Forms]![Form1]![txtStartDate] And [Forms]![Form1]![txtEndDate] " & _
  10. "AND tblTest.Location=[Forms]![Form1]![txtLocation]" & strSQL 
  11.  
Jun 10 '10 #26

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

Similar topics

8
by: Reply Via Newsgroup | last post by:
Folks, I am using Apache 1.3.x with PHP 4.3.x and MySQL v4. Short question: Before I put my web form available on the internet, how can I test it from mis-use in such that special characters...
1
by: champ.supernova | last post by:
Hi, I have a form which has a few different submit links, all of type image. This is critcal to the operation of the form, as it relies on the image co-ords being passed to another page, the...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
7
by: Mike | last post by:
I have to pass a date from a form to a report query. I have written a query that works fine when I execute from SQL view, But I dont know how to pass a value from the form to this query. SELECT...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
6
by: neelay1 | last post by:
Hi all, I have a Javascript variable that contains the name of a form input- input_name = "document.myform.ip" How can I get the value of this form input, "ip" using the variable input_name?...
0
by: arshadch | last post by:
Please let me know if any one can help me to input urdu data and create report using vb 6. I am using access 2003 database. Input in urdu and report are working using access forms are report but not...
8
by: Phil Latio | last post by:
I've been creating an application over the last few weeks and generally pleased with what I have produced but one area is irritating me, form validation. At the moment the forms are simply...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: PotatoChip | last post by:
I am working in Access 2002 and I have been asked to create a form for a report based on a paramter query so that the user selects the department from a drop down list on the form, query runs and...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.