New fields won't show up in VBA (1 Viewer)

klox

Registered User.
Local time
Today, 14:10
Joined
Aug 24, 2005
Messages
10
I added about 15 new fields to a table and added textboxes bound to those fields in my form, but when I go to the VBA code I can not access any of those fields, just the textboxes I made. I have no clue why, I wonder if its some kind of refreshing whatever the VBA code is linked to but that doesn't sound right to me.

An example of what I am talking about:

I added a field called Car3 to my table.

I created a textbox bound to this field called txtCar3

In the VBA code I am able to do Me.txtCar3, but I am not able to do Me.Car3

I could continue doing all my code by accessing whats in the individual textboxes, but the rest of my code uses Me.Fieldname so it would start puting inconsistencies in my code which I am not to fond about. Anyways, thanks for any help/advice/words about this.
 

WayneRyan

AWF VIP
Local time
Today, 20:10
Joined
Nov 19, 2002
Messages
7,122
klox,

TextBox properties:

ControlSource: Car3 <-- Access will synchronize this with the value in your table.
Name: txtCar3 <-- The name of your textbox, refer to it by using Me.txtSomeTextBox.

You want to reference your controls (textboxes & such).
You don't really reference your tables directly.

btw,

15 new fields ... Car1, Car2, Car3

Use the Search Facility here and look for "normalization". It sounds like
you're building a spreadsheet.

Wayne
 

WayneRyan

AWF VIP
Local time
Today, 20:10
Joined
Nov 19, 2002
Messages
7,122
klox,

Just realized. You probably had the Wizard make the original form.

It will have the same value for the ControlSource & the Name.

Wayne
 

klox

Registered User.
Local time
Today, 14:10
Joined
Aug 24, 2005
Messages
10
I didn't use any wizards. I set each controlsource and name for all the objects on the form.

So accessing the txt's would be better than accessing the direct control, thats what I had a feeling people would say. I still don't understand why the controlsources wouldn't show up for the new fields I created in the table and bounded to the new textboxes I made would not show up as an option in VBA. I will just resort to using the form names.

Its not a spreadsheet, but I will look into normalization.
 

WayneRyan

AWF VIP
Local time
Today, 20:10
Joined
Nov 19, 2002
Messages
7,122
klox,

When you make a new textbox, Access gives it a wonderful name
like "Text16".

The 1st thing to do is give it a meaningful name like "txtHoursWorked"
and then set its ControlSource to the right table column.

In any code (or formulas), you refer to it by "txtHoursWorked". Only
the underlying Access Software cares about the Control Source and
keeping the data in synch with your table.

Wayne
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 19, 2002
Messages
43,384
Forms/Reports don't refresh their fields collection when they open. That means that if you add fields to the RecordSource after the initial creation of the form, they can't always be "seen". To resolve the problem, you must make the form/report refresh its fields collection. Do that by deleting the query or table name from the RecordSource, saving the form/report and then replacing it.
 

klox

Registered User.
Local time
Today, 14:10
Joined
Aug 24, 2005
Messages
10
Yeah I give all my textboxes meaningful names, along with all fieldnames, but most of my code deals with direct changes to each record, but I will probably start switching to updated the textboxes instead of the table's data directly.

Anyways, making a copy of the form and renaming it and deleting the old one and renaming the copy to the original name worked perfectly. Thank you all for your help, learned a lot =]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 19, 2002
Messages
43,384
Anyways, making a copy of the form and renaming it and deleting the old one and renaming the copy to the original name worked perfectly
That isn't what I said to do but apparently that also makes the form refresh its fields collection. I think my method is easier though.
 

klox

Registered User.
Local time
Today, 14:10
Joined
Aug 24, 2005
Messages
10
You way didn't refresh the connections. The table fields still didn't show up in the VBA code, but when I refreshed the entire table it showed up.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 19, 2002
Messages
43,384
I always use queries. Maybe it works differently.
 

Users who are viewing this thread

Top Bottom