Else if statement ??

M

Mike Wilson

Help please

I am trying to put together an if statement to run a
proper case module and also to to transfer
the contents of a field to another subject to the field
being blank.

The code I am trying to use is:
Private Sub Name_AfterUpdate()

If Len(Me!Name) > 0 Then
Me!Name = ProperCase(Me!Name)
Else
If (Me!Comp) = Null Then
Me!Comp = ProperCase(Me!Name)
End If
End If
End Sub

The Comp field is for Company and if it is null then I
want to transfer the Name field to it, I tried splitting
the code to transfer the Name field to the Company field
using the on enter event...but had no success

Any help gratefully appreciated

Thank you

Mike
 
W

Wayne Morgan

Mike,

A couple of problems.
1) Don't use reserved words as names of fields, controls, etc. The word
"Name" is a reserved word. If you had used Me.Name instead of Me!Name you
would have returned the name of the form. I recommend that you change this
name. Also, you shouldn't have any 2 items with the same name. By default,
if you just drag a field to a form, the control for that field will have the
same name as the field. This can also cause problems. I usually fix this by
changing the name of the control by adding a prefix to it. The prefix
depends on the type of control. For example, if the field is BirthDate and
the field is a text box then I would name the text box txtBirthDate. For a
list of common prefixes, check here.
http://www.mvps.org/access/general/gen0012.htm

2) Null is a special state. There is nothing there if the value is null,
therefore there is nothing to be equal to. Try this instead:
If IsNull(Me!Comp) Then
Me!Comp = ProperCase(Me!Name)
End If

3) The syntax of the Else part is off a little, although it should work. If
you are going to add another If to the Else part, try it this way.

If Len(Me!Name) > 0 Then
Me!Name = ProperCase(Me!Name)
ElseIf IsNull(Me!Comp) Then
Me!Comp = ProperCase(Me!Name)
End If
 
M

Mike Wilson

Wayne

Your revision to the code I posted works out well

Thank you for this, I'd better do some reading and make a
few changes.

Many thanks for your help and support

Mike
 

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