Select certain rows from a result set. MS Access VBA - sql

This could be bit complicated. I will try to explain as much as I can.
Say for example i have a table called "Job". In this table there will be multiple entries for a same Job ID (Job ID is not Unique). The current system enables a user to search for a particular Job ID and return all the rows having the same Job ID on a form as shown below:-
Job ID | Item Name | Date Completed | Generate Report?
------------------------------------------------------
JB001 Door 25/12/2012 []
JB001 Window 02/01/2013 []
JB001 Blinds 10/01/2013 []
JB001 Carpets 15/02/2013 []
I would like to implement a feature where a user can select multiple rows from this result set (using the check boxes) and generate another form/report form he selections. For e.g. if the user ticks check boxes next to Window an Blind and then clicks a button, the next form should display these selected rows.
By the way, I am using MS Access.
The problem I am facing is haven't got a clue as to how to implement this i.e to select certain rows from the result set.
Thanks in advance.

Perhaps youre thinking in too much code, could you formulate a query that uses the job ID from a form and the check box as a where condition?
You could base the report off of the query and as long as the form is open when the report is opened the query can use its fields. In the where box type [Forms]![frmFormName]![FieldName]
That should get you started.

Related

Showing Stats on data with 2 Input Date Fields Apex 5.1.0.00.45, Windows

I have a table with 2 date fields and other columns. I have to be able to show stats on some of these columns between 2 dates that can be selected from a dropdown list.
All of this must be done in Apex. The client must be able to select a Start Date and an End date and then the count of for instance the number of Referrals between 01/SEP/17 and 30/SEP/17 must be shown.
The SQL code I used in Oracle to achieve this is:
select
'Total Referrals' as Details,
count(REFERRED) as Total
from PD_PATIENT_DETAILS where REFERRED = 'Yes'
and EVENT_DATE BETWEEN to_date(:EVENT_DATE) AND to_date(:EVENT_DATE_END);
I am now struggling to get this build in Apex. I only started working with Apex when I was brought onto this project. Have never worked with this before and am currently the only one working on it.
You can create 2 seperate page items and make them datepicker fields (P1_EVENT_DATE and P1_EVENT_DATE_END)
Your SQL query could look like this:
select
Total Referrals as Details
, count(REFERRED) as Total
from
PD_PATIENT_DETAILS
where
REFERRED = 'Yes'
and EVENT_DATE between :P1_EVENT_DATE and :P1_EVENT_DATE_END
Then you need to make an dynamic action (on change of one of the items, or make a go button) which submits the page or refreshes the report region (then you have to set the page items into the session state).
Something like this

MS Access manual Auto incrementing field

Im building a system for my company to keep track of internal orders, inbetween our warehouses, we have material that goes out warehouse 1 to warehouse 2 and we kind of lose track of how much of "x" is in warehouse 1 and how much in warehouse 2, so i want to implement this access db where a user fills a form and says: order 1: 500 of "x" order 2: 300 of "y". then another user fills an exit form where he says 1 of "x" going out, so i would need the program to keep track of total order and how much as gone out to fill order 1 and so on...
My idea here is to have both an order number and an id number for each of "x" everytime someoneone assembles 1 "x" they fill the form and print a label directly from the access (i have this part working already) while keeping a record of when it was assembled, who verified and what was verified (it will work as a quality control also).
What i dont know is how to program the db so when it reaches 500 of "x", the id number for "x" starts again from 1
This is the one major issue with my program right now, i'm not experienced in access db's or vba, but im getting there with a tip and a trick from here and there, so, no need to be careful with the technical language, i will google it if i have to :p
EDIT:
The table structure goes as follows:
1 table as the main table where I record the check that is made for every product, where I include the model of the product, the said ID that I want to reset after a number of products checked, and a concatenated field that includes most of this information to generate a qr code.
Then there is a table for the Order Number, which is connected to a form to record each new order with a date/time field, the order number itself and the number of products. This number of products must then be called from the code that will count how many products have been checked to date and keep the order number field updated so we can keep track of the order.
Then there is another minor table just to get values for the form, the product models
Thank you for your answers ;)
See this MSDN Documentation
Unfortunately in Access, you cannot 'reset' an ID field, unless you move the records to a newly created table and use that table for every 500 records.
As for the user control and login form, I'm afraid those are separate questions that must be asked in a different thread.
To get you started:
You can set the RecordSource of a form to a table, and when users make entries, the data will be saved to the table. You can also use a form with controls (text boxes, comboboxes, etc.) and create a button that runs a query to insert these records into a table.
The login piece - you can encrypt the database with a password. That may/may not be sufficient.
I would suggest you change your schema, if possible. Something like the following:
Orders
OrderID (Autonumber)
ProductID (link to your Products table)
QuantityRequested
Deliverables
DeliverableID (Autonumber)
OrderID (link to your Orders table)
SequenceNumber: in the BeforeInsert event set this value equal to:
DCount("*", "Deliverables", "OrderID=" & Me.OrderID) + 1
I'm assuming that your form has a control named OrderID that is bound to the OrderID field of the Deliverables table.
The code uses the DCount() function to get the count of all the other deliverables that have already been created for this order. If this is the first deliverable, DCount() will return 0. It then adds 1 to this count to get the sequence number of the next deliverable.
If the new SequenceNumber is greater than the quantity requested, you could display a message saying that the order has been filled and cancel the creation of the Deliverable record.
This is just one approach and it is not a complete solution. I'm assuming that once assigned a sequence number a deliverable cannot be deleted. You might need to make allowances for deliverables that get lost or damaged. You could incorporate a status field to the Deliverable table to deal with this, but you would still need to make a decision about what to do with the SequenceNumber.

VBA, SQL, Queries

I have an access form with few controls on it, like start-date, end-date, move_type, mover_name etc, when user fills this field n clicks on query command button, a select query is run and it fetches records from various tables depending upon the criteria mentioned by the user.
Later the same records are exported to excel file and a report is generated for user.
Now I need to do more with this, my select query has a field "quoted-price", depending upon the price quoted the records need to be sorted out.
EX : if quoted_price < 500 then it is a "domestic apartment1", if quoted-price is >500 And <1500 it is "domestic Apartment1" etc.
Now I need to do more with this, my select query has a field "quoted-price", depending upon the price quoted the records need to be sorted out.
EX : if quoted_price < 500 then it is a "domestic apartment1", if quoted-price is >500 And <1500 it is "domestic Apartment1" etc. and when all the records generated through select query are searched on this criteria, the records need to be grouped accordingly. Later the count for individual category is multiplied by a unit value and total charge is calculated.
I tried building many queries to do this and tables to refer to value but of no use. Any help will be much appreciated.
are you looking to create a new field depending on the condition? That may be step one of what you are trying to do, If so that is pretty easy. See here: http://allenbrowne.com/casu-14.html

MS Access Combo Box Selections and Time Calculation

Hi currently i am making a Table with 21 Columns ("Task, Name, Time Taken") Each group, so total 7 groups.
Task combo consist of "WIP, HOLD, Quality Check"
Name combo consist of "Mark, John, Alex"
Time taken is a number field "only minutes" like 150, 200, 300 etc
At the end i have 3 columns which is for total time taken for "WIP, HOLD, Quality Check"
My Requirements:
a) When i select a Task (eg. WIP) auto the name should block with the user logged in "I have created a employee table with login form its working fine"
b) When the task selected as "WIP" and entered the "Time Taken" may be multipal times wit there groups. only the WIP total time should calculate and reflect on "TOTAL TIME TAKEN for WIP column"
Please help me ... it may be confusing but let me know if your unable to understand.
Thanks in advance.
What you're describing doesn't sound normalized at all. I'm not entirely clear on your situation but I believe you need to have two at least two tables. If you don't know what normalization is then
What is Normalisation (or Normalization)?
is a good place to start
As for the last 3 columns with the total time. You shouldn't put that in a table. Once you have a table you should always have a query total it up for you.
First of all, your table should have 5 columns. ID, Task, Name, TimeTaken, GroupName. Unless you have a need to show 7 groups simultaneously on the same form? You can filter the data at any time based on GroupName.
For part a, it sounds like your login form should be able to feed your Name combo? Just set ComboName.SelectedValue to whatever your user's name is.
For part b, I just don't understand what you're asking. Can you clarify?

MS Access 2007 - Select multiple records and assign a value into a field

I am using a Multiple Items Form to list CASES (records) where there is no TECHNICIAN assigned (Maybe I should use a Datasheet to list the records?).
I would like the user to select a TECHNICIAN from a dropdown field that gets its values from an Employee Table (I can do this). Then I would like the user to select multiple CASES (records) in order to assign that one TECHNICIAN to the Technician field in all of the selected CASES.
Basically, I'm trying to keep the user from having to assign a technician from within each and every incoming case request. I want them to "batch" assign a tech to multiple cases.
Can someone point me in the right direction?
Ok so I did some more research. This may not be the best answer but it works for now.
I created a Multiple Item Form.
I added an unbound dropbox that lists Employees from the table
I added a button on the detail section (for each record) with the follow line of code:
Me.Technician = Me.Choose_Technician
Now the user can pick a technician from the dropdown and then click the button to assign that technician to the record/casefile.
This is a simple solution if you only have a couple of records/casefiles to assign. If the amount of incoming casefiles increases there will have to be a way to select multiple records using the shift key. I'll keep researching this.