how to create a multi field query in access 2007? - mysql

guys
' i am beginner in access 2007 and i want to create a form that contains many fields (product id, product name, etc and date of transaction) and use a query to search for data
in other words for example i want to enter in this form a date range i.e from 1/1/2013 to 1/03/2013 and search for product x ( attention ) my basic table contains only date of transacton field and not the from, to fields ( the from , to fields i want only to add them in the search form and them to search based on the value or date of transaction field ) please help me

Short but sweet answer;
Create a new "Query" using the GUI. Add your table to the top part. Double-click columns in the table to add them to the output of the Query.
Next, in the query conditions (grid below the name of each field) use brackets "[]" around your from/to dates. E.g. the query condition underneath your date field may be;
"between [MyStartDate] and [MyEndDate]".
Now "run" the query to test it; Access will prompt you for 'MyStartDate' and 'MyEndDate'.
Finally; if you save this query and set it as the "Data Source" for a Form, you may alter the above condition slightly to pull the values automatically from the form itself, so that you are not prompted every time the query runs. E.g. this condition may be;
"between Forms![MyTableForm]![MyStartDate] and Forms![MyTableForm][MyEndDate]".
You will have to play with it a little, but those are the basics.

Related

How to get combo box selection to fill related fields with data

I have a table [inventory] with inventory items, and a bunch of columns with different information for those. Mainly, part#, description, price. I am trying to create both a purchase order form [POForm] and, and a inventory transactions form [TransactionsForm], but that one thing I've been stuck on is getting a combo box look up I use to select the part# from [inventory], to also fill my fields for description, and price for that item in my form. I need the fields that are filled to be able to have formula's run off of them, and the information to be saved into the table for that form [TransactionsTable], [POTable].
I've tried making my part# combo box include the fields for the description and price, and using =[part#].[column](x) in the other fields as a lookup, and it looks right visually, but that is apparently just a visual of that data, but technically the field is still blank, because those other fields remain empty in the table for that form, and I am not able to run a formula off the price.
As per my understanding and please correct me if I am wrong. you have a form that shows your inventory data Part# Description & price. This form has a combo box that allows you to select a particular part # to view its related record data description and price.
Now you want to click a command button after selecting a particular part # to update your transaction form and POtable.
1.you have to create a query,
2.insert the inventory table in it
3.select append from the query type in the ms access ribbon
4.a window will appear, choose the transaction table as the destination table to append to.
5.double click on the fields that you want to retrieve its data from the inventory table
6.then in the table below in the query itself in the "append to" row you will find drop-down menu including all the fields from the transaction table. choose the corresponding fields. note if the fields have the same name in both tables access will do it automatically.
7.in the criteria row type the following [Forms]![Inventory Form Name]![the name of the field in the form]. do that for each field in the happen query.
8.save the query and name it
9.go-to design view in your inventory form and create a command button, in the click on event creat macro of the following: openquery-->type the append query name
10.save and close macro builder
11.open your form, select part#, click on the button
12.access will ask you to confirm appending process. click ok/yes
13.check your transaction table to confirm that the append process was successfully performed
14.Tip if you do not want the confirmation msg of append to appear, in the click on event go to the macro builder and choose in the ribbon show all actions then in the first line of the macro builder insert setwarnings - NO
the same is to be applied for the POtable.
Anyways, I hope you find this clear and helpful but I have only one concern you do not have to append part description and price in transaction and PO tables as you already have this data in your database in the inventory table. Generally speaking no need to include the same information in multiple tables otherwise you are not benefitting from the idea of a relational database.
I hope I addressed your inquiry.

Sequential Number in Access Form Based on Field Selection

Hoping someone can assist here, I'm fairly new to SQL but yet the most experienced person in the office so this job has fallen to me.
I'm trying to build a form that will insert customer orders into production scheduling. The form allows users to select a machine from the machine list table, however what I need it to do after that is find the last job number for that specific machine and show the next sequential number in a text box; and that's where I'm stuck. The goal is that when the production user is adding an order to the database, by selecting their machine the next available job number is automatically populated. The information entered will be saved to a master scheduling table.
I've got a query built that pulls the entire list of machine and job combinations, as my goal was to build a macro that could search from that list, but so far I haven't gained any traction. Any help/advice would be appreciated!
Welcome to SO.
My suggestion would be to create a table to hold the sequence numbers. For the sake of this example, let's call it ProdSeq, which means Production Sequences. As part of this table definition, I would use Data Macros (Access 2010 and up) in order to assign the sequences as records are added. I would use a Unique index in order to ensure no duplicates are created.
Table: ProdSeq (Field Definitions)
MachineID (Number - Long) - References Machine ID in Machines Table
ProdSeq (Number - Long) - Incremented for each machine
OrderID (Number - Long) - References Order ID in Orders Table
Indexes
Under the Design ribbon tab when designing the ProdSeq table, click the Indexes button.
Create an Index called UniqueKey
Row 1: Index Name = UniqueKey, Field Name = MachineID
Row 2: Index Name = Leave Blank, Field Name = ProdSequence
Click on Row 1, Column 1 and set the following Index Properties:
Primary = Yes
Unique = Yes
Ignore Nulls = No
Data Macros
Under the Design ribbon tab when designing the ProdSeq table, click the Create Data Macros button, and then the Before Change button. Enter the following data macro: (Pastebin link)
Create the Before Change data macro and set it as follows:
If [IsInsert] Then
SetLocalVar
Name LatestProdSequence
Expression = 0
Look Up A Record In ProdSeq
Where Condition =[ProdSeqLookup].[MachineID]=[ProdSeq].[MachineID] And
[ProdSeqLookup].[LatestSeq] = True
Alias ProdSeqLookup
SetLocalVar
Name LatestProdSequence
Expression =[ProdSeqLookup].[ProdSequence]
SetField
Name ProdSeq.ProdSequence
Value = [LatestProdSequence]+1
SetField
Name ProdSeq.LatestSeq
Value = True
End If
Pay special attention to the fact that only one SetLocalVar is within the LookUpRecord clause. Use the collapse / expand (-/+) button on LookUpRecord to make sure.
Create the After Insert data macro and set it as follows: (Pastebin Link)
For Each Record In ProdSeq
Where Condition = [ProdSeqFlagFix].[MachineID]=[ProdSeq].[MachineID] And
[ProdSeqFlagFix].[LatestSeq]=True And
[ProdSeqFlagFix].[ProdSequence]<>[ProdSeq].[ProdSequence]
EditRecord
SetField
Name ProdSeqFlagFix.LatestSeq
Value = False
End EditRecord
Test it Out
You can create this in a blank database in order to see what I am talking about. You should be able to adapt it to your specific situation.
Form
On your form, when the user selects a machine and order, you can use VBA in order to check for an existing record in ProdSeq, and fetch the ID. If no record exists, then you can create one, and then return the ProdSeq ID to the form.
Note: Depending on your design, you may also need to create a Data Macro on the Schedules table. Suppose someone creates a schedule with a specific machine and order and reserves a production slot. Now assume they change the Order ID .. we have a production slot reserved in error. So if this applies, you'll also need an AfterUpdate data macro on the Scheduling table that checks to see if [old].OrderID <> [Schedule].OrderID - and if they do differ, to remove the Production slot from the schedule table and the Prod Sequence table.
As I understand, you need to add suggested value for job number when you add new record to the table. If so, you can use, for instance DMax function. Here is example of VBA code for this, it can be called when you add new record:
Me.MyTextBox = DMax("JobField", "JobsTable") + 1
I supposed that JobField, which contains job numbers has Number data type.
Also you can use this function inside any query as a calculated field.

Access - Enter Parameter Value Error

I have a table that contains all the weeks of the year (using the client's numbering, so Week 1 is in June), and the dates they start. There is a form where they can choose which week they want to look at, so I've used a ComboBox that grabs all the week numbers for which they've entered data in the WeeklyHours table, using
SELECT Format(WeeklyHours.Week,"0") AS Expr1 FROM WeeklyHours GROUP BY WeeklyHours.Week;
This combobox is then supposed to be used as the week filter for a couple queries I've built, using the combobox value as the matching criteria. The problem is that when the form is closed, those queries can't run, and give me the Enter Parameter Value error for the combobox value.
To fix this, I tried to create a new table called SelectedWeek with a single entry called Week_Number. There is then some AfterUpdate code that saves the selected combobox value to the Week_Number field of SelectedWeek.
I then changed the queries to point to [SelectedWeek]![Week_Number], so that the queries will always use whatever the most recently selected week was.
However, I keep getting the Enter Parameter Value error for SelectedWeek!Week_Number, and I can't figure out why.
Any help would be most appreciated.
Thanks,
Joel
Reason the user is prompted for Parameter Value (by the way, it is not an error) is in both cases the Access SQL engine cannot see either referenced values. In first case, the form is closed and in second case column is not properly aligned to a lookup.
In first scenario, simply keep form open which user selects value from combobox when running other queries. Otherwise, all content on form is not callable since it is closed from memory:
SELECT * FROM TableName WHERE weeknumber = Forms!FormName!WeekNumber
In second scenario, use a DLookUp() part of the Domain Function Family.
SELECT * FROM TableName WHERE weeknumber = DLookUp("Week_Number", "SelectedWeek")
And really, domain functions can be generalized as subqueries in SQL:
SELECT * FROM TableName
WHERE weeknumber IN (SELECT Week_Number FROM SelectedWeek)
Even more, you can run a cross join query (tables separated with commas in FROM clause) of the two tables and avoid lookups. Below assumes SelectedWeek is a one-row, one-column table but with the WHERE condition, length is handled and you can explicitly declare columns in either table:
SELECT *
FROM TableName, SelectedWeek
WHERE TableName.weeknumber = SelectedWeek.Week_Number

How to match text to a defined numeric value

I have a database that has a bunch of survey data that I would like to work with. For several questions, the values are things like "Very important","Not at all likely" and I want to create a calculated field to assign a numeric value to these responses.
I don't want to replace the responses at all since I am going to have a user fill out a form to append the data set. I do want to have a calculated field that will automatically assign a numeric value to a text response.
I would just use a vlookup or an IF function in Excel to do this, but the problem is that Excel can't handle as much data as Access can. I need to set it up so that all Excel will house is a pivot table from the Access database.
Could anyone please tell me if there is a good way to do this? I am just not sure how to do it.
Create a new table with 2 columns: user_value (text) and numeric_value (number). Get all of the user entered values uniquely from the user entered data table with a query (the sigma symbol gives you a group by query). Put these in your new table and assign a numerical value to them. Then you can create an output query which joins your data to the lookup table and retrieves the numerical value for each user entered value.

SSRS Report Parameter with 500+ values

One of the parameters I have in my SSRS Report is called Customers. The user wants to be able to select multiple customers from a drop down list. Our customer list is over 500+ entries long. How can I get that many values in a drop down list. For that matter, how many values will a parameter handle? Is there a way to set the drop down list to be able to be typed over to prompt values? An example of that last question would be like how on most forms that ask for the state you live in, you can click on the list and type "TX" and it will move down to Texas instead of having to scroll down. I hope that makes sense. Thanks for all your help in advance!
You cannot have the parameter's field to behave with Autocomplete text.
And I agree that having 500 values in small field is not user friendly.
My suggestion is to split the parameters into 2-4 different parameters (in order to make the customer search more easy), each parameter will have the customers name according to the ABC (for instance the first params will contains the customer names from A-I,second J-R,last S-Z)
If so, your query should look like the following:
SELECT customerName,customerAddress,customerCity,...
FROM customerTable
WHERE (customerID IN (#customerParam1) OR customerID IN (#customerParam2) customerID IN (#customerParam3))
I don't know the how to do the second part with typing in a value but I can help with how to setup the drop down list. First write a query that selects the customer name and unique value for the customer.
Example:
SELECT CUSTOMER_NAME, CUSTOMER_ID
FROM CUSTOMER_TABLE
Then add the parameter and select your data type and the check box that says "Allow multiple values". Then in the properties click the "Available Values" tab. Once that opens select "Get values from a query" and select the the query you just wrote. Once that is selected go to the "Value" field and select the unique value from your query and for the "label" field select the customer name and they should all show up.
When using the values from the parameter in your main query you will need to make sure you use the IN function and not =. This is because you are not getting just one value back but all of them at once.
Example:
SELECT CUSTOMER_NAME,CUSTOMER_ADDRESS,CUSTOMER_CITY,...
FROM CUSTOMER_TABLE
WHERE CUSTOMER_ID IN (#CUSTOMERNAMEPARAMETER)
The name of the parameter is what variable name you need to use.
Also just another tip you can have them all default to selected by going to the default values and select "Get values from a query" and select your query and unique value again.
Also I don't think there is an issue with a number of items limit on the list box. I've had it up to almost 1,000 and had no issues.