简体   繁体   中英

How to bind textbox controls per row in access 2003

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:

  1. Continuous Form to display a list of invoices from an Invoice table.
  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM