I have a MS 2010 Access Report that needs to be populated by records that a user pre-chooses. For example.
Form1 has 2 fields, LOT# (which is record id) and CheckoffBox (unbound).
User checks which Lot#'s (records) he wants displayed, then clicks REPORT button. Report only shows selected records.
Can someone help me create the code?
In order to allow the user to use a check box to select multiple records, the list presented in form 1 must be based on a table that has LOT# and a yes/no field. (ie form 1 must be based on a query or a table that ahs this yes/no field).
If only one user will ever use this at any one time then you can simply add a yes/No field to the table that has all the LOT# values.
On your report you then only print those lot numbers that are checked.
Your report simply has to have SQL with a where clause that only print records that have the Yes/No field ticked. (=true =-1).
If many users are going to use this form at the same time it gets more complicated as obviously they all need to have their own "set of yes/no fields".
So you would need to copy the table with the LOT# into a temp table for use by each user (it might have a primary key of USERID, LOT#, or it might be a table with just LOT# and yes/no fields, that only a user can access - ie in their own copy of the database file that has the front end forms).
Anyway, assuming it's a single user, creating the above should be quite straight forwards.
On opening form 1, you might use the form_open event to run a SQL statement that sets all the Yes/No values to No. Although you might not want to do this.
Use
docmd.SetWarnings false
Docmd.runsql "UPDATE theTable SET YesnoField = 0 WHERE YesnoField = -1;"
docmd.SetWarnings true
Let me know if you can take it from here.
Related
Our current Switchboard displays a msgbox with the date and time of the most recent records update. This is a discretionary call, and not all changes in records result in changing this value. The Switchboard On Load form event contains the msgbox code. I want to eliminate the msgbox edits and replace the msgbox with a subform on the Switchboard that displays the most recent value of a field in table subUPDT.
Table subUPDT contains two fields, UPDTID (autonumber) and UPDT (date & time). How do I program the command button (btnUPDT) on the Switchboard so that it inserts the current timestamp into subUPDT.UPDT and then refreshes the Switchboard to display the most recent value?
As you have likely deduced, I am not a professional programmer. I do realize this may not be the most refined approach and am open to suggestions. Thank you for any assistance.
So I looked at the INSERT function as suggested (Thanks, HansUp!), but then decided that I preferred to update the existing date entry instead of creating a growing table with subsequent entries after each update. I chose the DoCmd.OpenQuery function to run a SQL update query when I click my Update Button.
The SQL query basically says:
UPDATE *SubTable A* SET *Last Update Field* = Now();
When I click the update button on my admin interface (form), it updates the Last Updated field in SubTable A with the current date and time. SubTable A contains a single entry for the most recent update timestamp. I then use that field in a number of forms to inform users, and myself, of the most recent, significant change to the table. Not an elegant solution, but one that works.
First of all, I am a total NOOB! I am trying to make an Access DB for handling orders through an entire process. As such, I have created tables based on each of the individual processes. The order data, which holds only the basic information is in tblCurrentOrders. Each of the other processes is linked to tblCurrentOrders by the OrderNumber field. The first step of the process is due date information is entered in the tblPlanner table. Obviously, until data is entered in tblPlanner, no OrderNumber exists (this will hold true for the other tables, too, if I ever get that far).
I want to create a form based tblCurrentOrders that shows only the records without corresponding entries in tblPlanner (new orders) and then I want to be able to enter the tblPlanner info in a subform. I have tried making a form based on tblCurrentOrders with a subform based on tblPlanner, but I can't figure out how to only display new orders. I also tried basing the form on a query that only showed new orders, but I don't know how to make the subform based on tblPlanner to work.
Please Help!!
Well, the easiest way to link the tables would be to create your OrderNumber in the tblPlanner when you start a new order. Then add a flag and timestamp as to whether it's "released" yet.
EDIT
Since you provide a little bit more detail, I'll edit my response to more closely align for your desired approach.
Creating a "New Order" is a multi-step process. So it's usually best to create a Command Button on a form that calls VBA code. This will allow you to control each step and make sure it's correct.
Step A: First you want to:
1) Create a Control Form (if you haven't already) that allows you to put Command Buttons which will launch different VBA code or open different display Forms.
2) On the Control Form, create a List Box that allows you to select an existing OrderNumber.
3) On the Control Form, create a Command Button to open an Order Form which uses the selected List Box OrderNumber. When that Order Form opens, it will populate with the tblCurrentOrders data for that OrderNumber and also populate the subform with tblPlanner data. (As long as you have them linked properly.)
4) On the Control Form, create a Command Button to open the Order Form with a set of records which are "New Orders" only. See the more detailed process below in Step C.
5) On the Control Form, create a Command Button to Launch VBA code that will create a "New Order". This is a multi step process detailed below in Step B.
6) Create any other buttons or controls that allow you to monitor or advance your "Order" along the way to completion. (This is a ton of work to get all the pieces in place.)
Step B: When you press the Command Button to create a "New Order" you want to create VBA code that will:
1) Create a new record in the tblCurrentOrders table.
2) Create a Unique OrderNumber on the new Record. It's usually best if you control the generation of this number and don't just let it be a system generated sequence number. But whatever you desire is ok as long as it's Unique.
3) Set your ReleasedFlag to false on the new tblCurrentOrders record.
4) Make sure your ReleasedTimeStamp is null. (Or whatever value you want it to be.)
5) You may want a CreatedTimeStamp which you can populate with a date of Now().
6) Populate any other "Initalization" fields that need to be filled. (Like Backorder status, Return flags, Shorted Flags, etc. etc. etc.)
7) Create a new record in the tblPlanner table.
8) Copy the Unique OrderNumber that you created for the tblCurrentOrders record into the OrderNumber field on the new tblPlanner record. This creates a link for you to use with your subqueries and subforms.
9) Now you can open the Order Form with this new OrderNumber.
Step C: When you press the Command Button to open a set of records which are "New Orders" only:
The Command Button needs to launch a query to find "...tblCurrentOrders that shows only the records without corresponding entries in tblPlanner (new orders)":
You just need to select tblCurrentOrders that have a ReleasedFlag set to false.
`SELECT * FROM tblCurrentOrders WHERE ReleasedFlag = false`
So when you say: "...and then I want to be able to enter the tblPlanner info in a subform"... you can create a subform linking to tblPlanner based on the tblCurrentOrders OrderNumber field.
This is all reliant on you observing that when you say "...records without corresponding entries in tblPlanner..." That you really mean: records without released entries in tblPlanner. And that means: in order for a record to exist in tblCurrentOrders, it has to have a corresponding blank (or starter) record created in tblPlanner. Thus now you can display blank tblPlanner records that are linked to unreleased tblCurrentOrders records.
Then once your data entry people are done monkeying around with the New Order, they can "Release" the order (usually by clicking on a Release Command Button). At that point, you can set your ReleasedTimeStamp to Now() and set your ReleasedFlag to True in the tblCurrentOrders. It's officially no longer a "new order" and is now a live order in your system.
You are at the tip of the iceberg for creating a home grown order entry system. The complexities for building a good one are immense. Best of luck figuring it all out. Just remember to use time stamps and ID fields so you can go back and un-do what may have been done by accident.
Hope this all helps. :)
I apologize for probably silly question, but I've already dont know which words to use for searching what i need. I have the good programming experience but am pretty new to Access.
I have a form with the controls, also it has a subform with read-only list of people contacts. This list is populated by a dynamic query from multiple tables, so i don't know in design-time the count and names of all fields. The user wants to be able to manually pick up several contacts from the list to send them a single e-mail.
I used to a table control allows user to select multiple records (usually with ctrl). But it turned out that in Access datasheet the continuous selection is only allowed.
Then I thought of adding editable checkbox column to a readonly table, where the user would be able to mark the desired rows. But I have not found a way how to do this in Access. It seems that the method Append in Fields collection is available only for tables and indexes, but not for queries or recordsets.
I have also read advice to get rid of the subform, and display data in listbox with property multiselect = extended. But in this case, the user will lose the benefits of the table: he can't move and resize columns, sort and filter data.
I have a feeling that the decision should be very simple, I just do not know the conventional way of how to implement this functionality in Access. Help me please.
This is doable by utilizing the RecordsetClone property of the sub form. Here is an example:
Sub GetSelectedValue()
Dim rs as Recordset
Dim sContact as String
Set rs = Me.[SubFormName Goes Here].Form.RecordsetClone
rs.MoveFirst
rs.Move Me.[SubFormName Goes Here].Form.SelTop - 1
sContact = rs![Recordset Column Name Goes Here]
Set rs = Nothing
End Sub
You can put this on the main form via a button control that takes the active row contact and places that name into a listbox on your main form. Once the user has made all their choices, you can then run your e-mail program off the names within the listbox.
If you want a datasheet (for filter, sort, resize), then an editable checkbox is really your only option.
The column can be part of the original table, or create a join table with ID and check column, where you add the IDs from all records of your base table.
In the subform you can set all controls except the checkbox to Locked = True.
I have a form with search fields and then the search results are shown in a subform below the search fields.
By default the subform loads all records prior to any search criteria being entered.
As this database grows the number of possible records to search will get quite large, so I don't really want the subform to load all records before the user attempts to makes a search.
What's the most performance-friendly way of loading the search results subform without showing any of the records to begin with?
I've considered setting the subform recordsource SQL to search for something I know will never be in the results... but I'm thinking that still requires the records to be loaded first and then filtered (might be wrong about this though).
Ideally I'd like the search results subform to load with the field names of the recordset only, but with no records until the user attempts a search.
Set the subform's record source to a query which returns a single manufactured row.
SELECT
0 AS id,
'' AS fname,
'' AS lname,
'' AS email
That will not pull any records from your table.
After you gather the user's search criteria, build the new SELECT and assign it as the record source.
Pretty simple explanation. I have a table with 10 entries, 5 entries with the year 2010 and 5 entries with 2011 in a column.
In the query I have, I use Like *2010 to filter out all entries equal 2010 and display onl those records.
On my form, I have combobox being populated with each unique year (from a different table). So my combobox values are 2010 and 2011.
Is it possible, when I select say 2011, I trim the right 4 characters and use as my Like criteria to refresh and requery the form, all done within VBA?
You can refer to the value of a control in a query run from within an Access session, as long as the form which contains that control is open.
SELECT *
FROM YourTable
WHERE date_field_as_text Like "*" & Forms!YourForm!YourCombo;
So perhaps you can use a similar query as your form's record source, and do Me.Requery in the combo box's after update event.
If that's not close enough to what you want, please give us more information about the data types of the fields involved. Adding brief samples of the table data to your question could also help; please make it clear whether the "date" fields are text or Date/Time.
Yes, it's possible.Just add your stuff to the 'YourComboName.After_Update'.
Look for the Events of the Form that are fired before the form is shown. There build your query as like HansUp suggested.