A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Else if statement ??



 
 
Thread Tools Display Modes
  #1  
Old May 12th, 2004, 06:54 PM
Mike Wilson
external usenet poster
 
Posts: n/a
Default Else if statement ??

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

  #2  
Old May 12th, 2004, 07:15 PM
Wayne Morgan
external usenet poster
 
Posts: n/a
Default Else if statement ??

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

--
Wayne Morgan
Microsoft Access MVP


"Mike Wilson" wrote in message
...
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



  #3  
Old May 12th, 2004, 08:01 PM
Mike Wilson
external usenet poster
 
Posts: n/a
Default Else if statement ??

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





-----Original Message-----
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

--
Wayne Morgan
Microsoft Access MVP


"Mike Wilson"

wrote in message
...
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



.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.