How to bind textbox controls per row in access 2003 - ms-access

I am new to Access programming and am trying to determine the correct way to bind unbound textbox controls for each row in a continuous form.
As an example:
Continuous Form to display a list of invoices from an Invoice table.
Table called InvoiceItems which contains equipment, rates and hours.
I need to have a form that has a row containing invoices with a column for all available equipment types.
I was planning on having unbound textboxes for each equipment type and then when each Invoice row is loaded, hook into something like an OnRowDataBound where I could dynamically populates the equipment textboxes with the appropriate data from the InvoiceItems table.
Example:
Tables:
Invoice: InvoiceID, Date
[1, 4/10/2011]
InvoiceItems: EquipmentID, Rate, Hours
[2, 40, 1]
[3, 20, 3]
Result:
InvoiceID | Date | Shovel | Plow | DumpTruck
==================================================
1 5/10/2011 3 1 0
2 2/11/2011 1 0 1
Then each textbox control would hook into the onDirty event to update the appropriate InvoiceItem line item.

You won't be able to do this in a continuous form or a datasheet view form since changing the ControlSource property on one row affects all rows.
It's unclear to my why you would even need this option but it sounds like your data/tables might not be designed properly or properly normalized. Usually I would build my tables so that EquipType is a value you can change to show what type of equipment this row is. It appears that somehow you are using different fields for each different equipment type.
Assuming that you insist on using your current design, you could possibly cobble together a solution using Union queries but your recordset will not be updateable.
Another suggestion is to make several different textboxes on your form and change the visible property on the fly. However, this is fraught with problems because you will only be showing one of them at a time on all rows. Furthermore, you'll have to show the correct one when they move to the next record but how are you going to determine which is the correct one to show?
Judging by what you've written, you must have experience programming in .Net. Access is a different beast and it works quite well if you play by its rules. Trying to get around some standard Access behavior or design will usually result in frustration for both the programmer and the user. I think this is a case where you will need to evaluate what you're trying to do and I recommend you start by making sure your table architecture is solid. Perhaps you've actually over-normalized and will need to go back and undo some of your normalization.

Related

Displaying desired information in a combo box

I am trying to create what I think is a simple access Database. Problem is that I am new to using access but familiar with programming and very familiar with working in Excel. I can technically and have already done the task in excel but what I really like about Access is the Forms. I would essentially like a user to use the form as they would my Excel document but since they would have limited control, there would be less room to mess up the process.
Anyways what I am trying to do is populate a field in a table with a number. However this number signifies a severity (e.g. 1 for low 10 for high). Each severity has a "map" or "gauge" that explains what the number means in severity (e.g. 1 - will not happen, 2 - rarely happens, 3 - sometimes happens, 4 - happens, 5 - always happens). What I would like to do is to have the user see from a dropdown list the number and associated severity meaning. Then what I would like to stay once selected is only the number.
Example case:
User wants to say that something sometimes happens. User clicks on the drop down list and sees this menu:
1 - will not happen
2 - rarely happens
3 - sometimes happens
4 - happens
5 - always happens
They click on the "3 - sometimes happens". Then what they see in the field that they have just edited "3".
I think this should be possible but I am unsure on how I would even go about this. I have only started with tables, I have not made queries or forms yet. I would eventually like the user to do this all on a form so that way they have limited access. For now I am simply trying to populate a table the way I think it should be made.
The best way to do something like this is to use a value list and then display two columns in the drop down but show only one in the combo box.
Step 1
Go to the Data tab of the properties. Set the combo box Row Source Type to Value List and then follow the below example for what to put into the Row Source:
1;"Will not happen";2;"Rarely";3;"Sometimes"; etc
Make sure the Bound Column is set to 1
Step 2
Then go to the Format tab and set the Column Count to 2. Set the Column Widths below it to 1,3 or whatever size suits your system the best.
If you want to use data from a table instead of a value list it's a simple matter of writing a query to select the two columns containing the number and info like below:
SELECT [Severity], [SeverityMessage] FROM TBL_SEVERITY
To use this simply replace Severity and SeverityMessage with the relevant column names in your table and TBL_SEVERITY with the name of the table. Then place this line into the Row Source and change Row Source Type to Table/Query
That should now be you set up with what you're looking for.

Access combo box for DB mapping table 2-1 Table relation

I've run into a bit of a snag with a project I'm working on, and being new to Access I don't know if what I want to do is possible without VBA. I've looked around but all I can find are answers related to showing multiple columns, not controlling multiple fields in my DB.
To paint a picture I have a mapping system set up in my DB to help me distinguish the name and type of data is held in a table.
The setup is as follows:
-Data table is "LineItems" with an ID and the line data (think typical excel format)
-Mapping table is "LineItem_Mapper" with LineItem_ID, DataType, and Entity_ID
-A helper table "Data_Type" with ID and Name
-two "Entity" tables with differing properties both have ID and Name
The reason for the split is on data type is that the two types of data behave differently. One type has a parent child relation, and the other is a standalone row. I want to preserve this structure in my DB and feel I have done so with this mapping.
Now, on to the issue I'm running into. In my Access data entry form I want to use a combo box, as the options a user may chose for each line when entering are finite. However, this combo box is affecting the Mapping table above. I have been able to populate the box with my desired list with a custom query built from my 2 entity tables, but I don't know how to get Access to create or update the Mapping table using this box.
what I want to happen is when I chose something in the box, a line is created (or changed) in the mapping table with all 3 columns being populated. first the LineItem_ID for the line I am populating, and then the DataType and Entity ID to reflect the proper mapping.
Can Access do this on its own? Or do I need to do this with VBA?
As requested by the OP converting my commend as an answer (with a little bit more detail):
By far your best option is to use VBA. I doubt there is another way and even if there is it would be so convoluted it would be unworkable and unmanageable.
This should get you started:
In the combo box properties go tot the events tab and in After Update or On Change (look up the difference between the two events to see which behavior you prefer) click the down arrow and select [Event Procedure], then click on the … button. This will create a VBA module for you complete with the function that runs when the selected event is triggered.
You can use DoCmd.RunSQL "[Access SQL INSERT statement]" to add records to tables.
You can use Me.[MyComboBoxName] to get the current value of the combo box. Similarly the value of anything else in your active form.
You can use DLookup to get the value of any record in your tables.
Hopefully these will give you a relatively quick start.

Access Form Field Logic

I'm trying to make access conditionally only show rows that meet a certain condition, allow me to give you some background info before I proceed :
I've created an Access form and linked it to a test DB on my machine. The particular table I am interested in contains the following (important) rows :
ID , Office, Name, SecurityNumber
The thing is, ID is not unique. There are two Office locations, and each Office has it's own set of unique ID numbers. This means that ID 10 here and there may or may not be the same person. (this data comes out of a legacy security system we're not looking to change yet, so I cannot change it)
But ID -is- unique to each Office.
SO! I created an Access form with TABS! Two tabs, one for each office. What I am trying to achieve now is :
Have the ID/Name/SecurityNumber fields for each tab populate with only rows that match it's particular 'Office' value.
Thank you for reading and thank you for helping! :D
If you want the data for the office locations presented in separate tab page controls, you could use subforms on the pages which differ only in the WHERE clause of the queries used as their record sources. So for the Office1 subform, the query could be:
SELECT ID, Office, [Name], SecurityNumber
FROM YourTable
WHERE Office = 'Office1'
ORDER BY [Name];
Then for Office2, the query would be the same except for the WHERE clause:
WHERE Office = 'Office2'
As I understand your question, that approach would do what you're asking for.
However, that's not really the easy "Access way" to do it. Instead consider a combo box control to allow your users to choose which office they want to view. In the code for the combo's after update event, either modify the SELECT statement used as the form's record source or create a filter expression an apply it.
Also, since you're pulling the form's data from SQL Server, consider whether you want your form to load every record for the selected office location. It may not be much concern if you have only a few to moderate number of rows for each location, but if you'll be dealing with multiple thousands of rows it could be. In general, you should try to avoid pulling copious amounts of data across the wire; pull sparingly instead ... only what you need for the immediate task at hand.

Getting the difference between two counts in Microsoft Access Report

I have a report which lists 2 fields namely appointments and absences. Now what I want is that after building the report, I want to get the difference between these 2 counts. Is that possible?
thanks!
If your report has two fields on it, Appointments and Absences, and they are named the same, create an unbound control and assign its ControlSource to be this:
=[Appointments]-[Absences]
Now, I wouldn't really recommend using that, since it's likely that the controls and the fields they are bound to have the same name. I'd rename the control that is bound to Appointments as txtAppointments and the one bound to Absences as txtAbsences, and the calculation would then be [txtAppointments]-[txtAbsences].
Now, keep in mind that this assumes that neither field is ever Null. If it is, you probably want this, instead:
=Nz([txtAppointments], 0)-Nz([txtAbsences], 0)
Try and see if it works!

Drilldown using unbound comboboxes with Access "Continuous Form"

There has got to be a simple(r) way to do this.
I have a situation where I am listing parts using continuous forms. The parts listing has things like the part type, manufacturer, part number and the quantity. The list is of the part instances & quantity. I can look the other things up from the instance of the part, so displaying existing parts is no problem, just use a joined query to retrieve the related records or using a DLookup to pull the fields individually.
Type Manufacturer Number Qty
-------------------------------------
Widget Acme 123ab 1
Widget Acme 456 1
Anvil Xyz 12345 2
Llama Northwind 322-12A 1
...
The problem is where the users need to add new parts. There are thousands of different parts, so they can't really choose from a single part number combobox. They want to be able select a part type, manufacturer, and then the part number from three different comboboxes that successively narrow the results in each combobox.
Select a part type >> select a manufacturer who makes one of those types >> select part number of parts of that type by that manufacturer >> enter quantity
Ok, so I can use 2 unbound comboboxes with a DLookup as default, and link them via their Row Source queries. The final combobox is part number with its Row Source filtered - so it only lists the parts from selected type and manufacturer. I have done that before with this kind of situation and it works well.
However I am trying to do this with continuous forms in Access and it is returning the same result for the Dlookup on each record. E.g.
Type Manufacturer Number Qty
-------------------------------------
Widget Acme 123ab 1
Widget Acme 456 1
Widget Acme 12345 2
Widget Acme 322-12A 1
...
Argh, what's going on? My Dlookups seem to be only using the value from the first record. Why?
Is this even a good way to do this? Is there a better pattern to use than drill-down comboboxes on the continuous form? The only other way I can think of to get around this is to use the comboboxes on a "add/edit part" type form where the details are selected in a dialog and then the part number is populated from that. But that seems even more kludgy.
Using unbound controls on a continuous form will only drive you demented, because an unbound control can only refer to the selected record, which could be any of them. I think the pop-up form for adding new records would be quite nice, and easy for the user to understand.