New field not found by VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have added an additional field to a table at a late stage, and this works
fine for putting a text box in a form to insert data, but if I put in a VBA
instruction Me.Newfield="Y", it does not does not recognise Newfield and
gives an error. Any suggestions?

Thanks
Dudley
 
Dudley,

If, in your form design, you added the control bound to NewField by drag
and drop from the field list window, then the control inherits the same
name, NewField. If, on the other hand, you manually added a textbox and
set its Control Source property to NewField, then the name of the
control is not NewField, as you assumed, it is TextX (where X is a
number). Am I right to guess that this is what happened? If yes, then
open the form in design view, select the control, display properties,
select tab Other and change the Name property from TextX to NewField;
alternatively, just see what the current name is, and use that instead
in your code.

HTH,
Nikos
 
Nikos,

Thanks for your help, but this does not seem to be the problem. The control
is called Newfield, and if I write code for the Newfield control, Me.Newfield
shows up, but if I try to use VBA from a control in another form to enter
data into the Newfield field, Me.Newfield does not show up. It appears that
because I added the field at a later stage, it only shows up erratically in
the list of fields etc when you enter Me. in VBA.
 
if I write code for the Newfield control, Me.Newfield shows up,
....and, of course, this only happens while writing code in the form's
own module.

but if I try to use VBA from a control in another form to enter
data into the Newfield field, Me.Newfield does not show up.
....which is to be expected. In each form's module, you will only see the
objects of that form in the list, not all forms' objects!

It appears that because I added the field at a later stage, it only shows
up erratically in the list of fields etc when you enter Me. in VBA.
Wrong assumption. It has to do with which module you're working in, like
I said above. In VBA, Me. actually means "the object this modile belongs
to", and it is just an abbreviation for Forms![The name of the current
form]. or Reports![The name of the current report]. In order to
reference a control on a form while in another module (either general or
form or report mosule), you need the full reference, like:

Forms![name of the form the control belongs to]!Newfield

instead of Me.Newfield (which only works in the form's own module).

HTH,
Nikos
 
Back
Top