access VBA code

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

Guest

Can someone interpret this Access VBA code for me?


Private Sub Form_Load()
[Forms]![Switchboard Items]![Manager1] = Nz(Manager1, "Enter Manager1")
End Sub

I'm coming from the Excel world and so am not familiar with Access' VBA
syntax. What exactly does this Sub do?

Thanks,

Dave
 
When the (unspecified name) form loads, the control named Manager1 on
the form named "Switchboard Items" is set to equal "Enter Manager1" if
it is currently Null (not empty, but null), otherwise it retains it's
current value.

Nz(Manager1, "Enter Manager1") is probably incorrect. should probably
look like:

Nz([Forms]![Switchboard Items]![Manager1], "Enter Manager1")

or if the form containing this code is "Switchboard Items" then this
is acceptable as well.
Me!Manager1 = Nz(Me!Manager1, "Enter Manager1")
 
Dave:

When the form loads the code puts "Enter Manager1" into the Manager1 control
(probably a text box) on the form if it is Null, i.e. does not already
contain a value. The Nz function returns the value of its second argument if
the first is Null, otherwise the value of the first.

Assuming this is in the Load event procedure of the form Switchboard Items,
instead of the fully qualify reference to the form, the Me keyword could be
used:

Me.Manager1 = Nz(Manager1, "Enter Manager1")

Note that the object names are not wrapped in square brackets here. This is
only necessary if the name includes spaces or other special characters as in
[Switchboard Items]. Note also that I've used the dot operator rather than
the exclamation mark. Nowadays the former tends to be favoured. The
exception is when a control on a form is referenced as a parameter in a
query, where the exclamation mark is still required.

Ken Sheridan
Stafford, England
 
Thanks, this is very helpful.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


Ken Sheridan said:
Dave:

When the form loads the code puts "Enter Manager1" into the Manager1 control
(probably a text box) on the form if it is Null, i.e. does not already
contain a value. The Nz function returns the value of its second argument if
the first is Null, otherwise the value of the first.

Assuming this is in the Load event procedure of the form Switchboard Items,
instead of the fully qualify reference to the form, the Me keyword could be
used:

Me.Manager1 = Nz(Manager1, "Enter Manager1")

Note that the object names are not wrapped in square brackets here. This is
only necessary if the name includes spaces or other special characters as in
[Switchboard Items]. Note also that I've used the dot operator rather than
the exclamation mark. Nowadays the former tends to be favoured. The
exception is when a control on a form is referenced as a parameter in a
query, where the exclamation mark is still required.

Ken Sheridan
Stafford, England

Dave F said:
Can someone interpret this Access VBA code for me?


Private Sub Form_Load()
[Forms]![Switchboard Items]![Manager1] = Nz(Manager1, "Enter Manager1")
End Sub

I'm coming from the Excel world and so am not familiar with Access' VBA
syntax. What exactly does this Sub do?

Thanks,

Dave
 
Back
Top