characters in code

tbcwarrior

Registered User.
Local time
Today, 20:58
Joined
Oct 10, 2006
Messages
26
i have a word in the code i am trying to write that has a - character in it (ie co-ordinator) and when i type in the code it spaces the word out like this co - ordinator

the code i have typed so far is
If Me.mortgage_co-ordinator.Value = "name" Then
Me.

but as soon as i hit the enter key after then it puts the spaces in co - ordinator

is there a way around this
 
all of the code

Private Sub Co_ordinator_email_address_AfterUpdate()

If Me.mortgage_co - ordinator.Value = "name" Then
Me.caption = "name@email.com"

ElseIf Me.mortgage_co - ordinator.Value = "name1" Then
Me.Caption = "name1@email.com"

ElseIf Me.mortgage_co - ordinator.Value = "name2" Then
Me.Caption = "name2@email.com"

ElseIf Me.mortgage_co - ordinator.Value = "name3" Then
Me.Caption = "name3@email.com"

ElseIf Me.mortgage_co - ordinator.Value = "name4" Then
Me.Caption = name4@email.com"

ElseIf Me.mortgage_co - ordinator.Value = "name5" Then
Me.Caption = "name5@email.com"

end If
End Sub

as you see the code has a space betwen the co and the -
co - ordinator

i am learning this by trial and error until i get myself some trianing
thanks

regards
chris
 
This I suspect is one of the reasons why spaces and special characters are not recommended either change the name or wrap it in brackets.
[mortgage_co-ordinator]. The best option is to remove the space and character altogether
 
I agree. You never want to use special characters or spaces in the name of a control. You WILL have more severe problems than just an auto-complete annoyance if you keep the control name like this.
 
What is going on is that the VBA environmentally sensitive editor sees that dash and says "AHA! A minus sign." So it automagically adjusts the "expression" to be more readable - by adding spaces around the "minus" operator. Change the minus sign.

OK, you say "dash"... doesn't matter. Whever Access thinks it is, it is. And Access will see that as a minus sign regardless of how you meant it.
 
And if you feel that you MUST keep the "-" in there, then you'll have to reference it:
Code:
Me.[mortgage_co-ordinator].Value

That's why it's best to not use spaces or special characters in object names: you have to do it different ways (and remember how to do it different ways) for different situations.
 
ok thanks guys

the code cant change for now as it is referenced by alot of other code i have, so i will need to put it in brackets.

i made this database when i didnt have a clue of the concept that i should use in access, but there are alot of people using the database so it will be a major change to remove the minus sign atm.

thanks again for the comments

very helpful

regards
chris
 

Users who are viewing this thread

Back
Top Bottom