Nomenclature: textbox names same as field names

Thirith

Board Regular
Joined
Jun 9, 2009
Messages
120
Office Version
  1. 365
Platform
  1. Windows
I expect there's an obvious answer to the following question, but I've not been able to find one: is the Access default of textboxes having the same name as the field that's the control source how it should be done? Since I lack enough experience and understanding of what's going on under the hood, I find it weird that there wouldn't be any problems with two distinct but related entities having the same name, yet that's what Access does as a default.

Are there any potential problems with this? Would it make sense to rename boxes on the form (e.g. txtFirstName instead of FirstName​, which would be the field name)? Or am I overthinking/worrying too much?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
When you add a textbox control to a Form, Access uses the name of the field as the name of the textbox. This is normal and logical. What other name would Access give? The reason there is no confusion internally, is because the table field belongs to the Tables Collection and the control on the form belongs to the Form Collection.

Best practice is to rename the control on the form to txtMyField. Although there will be no conflict (internally), it will make your code and maintenance easier.
 
Upvote 0
Thanks, that's roughly what I thought - though it should be easy enough for Access to rename the textbox itself. As you ask: "What other name would Access give?" You give the answer yourself: txtMyField. It's something that Access could automate easily; the fact that it doesn't made me wonder whether I misunderstood something.
 
Upvote 0
FWIW I don't rename my textboxes on bound fields. I leave them with the names access gives them (the same names as the fields in the table).
 
Upvote 0
Interesting. I always ensure the control names are not the same as the field names.
First, if code is involved, it is easier to distinguish between a control and a field when it's txtCustomer and Customer. I used to not worry about the difference but (and it was probably only one time) I encountered an "ambiguous name detected" or some other error as Access couldn't distinguish between the control and the field for what I was doing. So once was enough.

Besides, I'd rather read and write code that makes it clear that I'm trying to work with a property of a control rather than a field name. Sure, I'd understand that code isn't trying to apply backcolor to a field regardless of how it's written, but I prefer clarity for me and whoever has to deal with it later. That's just how I roll.
 
Upvote 0
That's fine. I've never encountered any problems or had any difficulties knowing what I'm doing (edit: meaning, how I am referring to controls or fields in my forms). I simply wanted the OP to know that it isn't necessary to change the names of the bound fields on a control.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top