access VBA code

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
 
S

storrboy

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")
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top