percentage once again

S

senkurion

I have a field called interest rate in table. Data in this table is in
percenatge I used following code ( which I got from Allen Browene ansewer to
similar qquestion in another post) I is not working for me please tell me
what is wrong with following code.

Code in module

Public Function MakePercent(Interest_rate)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named
Interest_rate to:
' =MakePercent([Interest_Rate])

If Not IsNull(Interest_rate) Then
If InStr(Interest_rate.Text, "%") = 0 Then
Interest_rate = (Interest_rate) / 100
End If
End If

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
and after update even of the text box is

=MakePercent([Interest_Rate])
but when i write this it says

expected: line number or label or statement or end of statement

i couldnot figureout waht is the problem
 
A

Allen Browne

Change the function back to exactly the way it is here:
http://allenbrowne.com/casu-16.html
i.e. do not replace:
txt As TextBox
with:
Interest_rate
etc.

Set the AfterUpdate *property* to:
=MakePercent([Interest_Rate])
not:
[Event Procedure]

If you wish to use an event procedure, the code to use would be:
Call MakePercent(Me.[Interest_Rate])
 
S

senkurion

Now the code in module is as below (exact copy as you said)

Public Function MakePercent(txt As TextBox)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named Text23 to:
' =MakePercent([Text23])

If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
(here i played by changing to interest_rate=interest_rate/100)
but does not work and by the way the format for the filed is %)
Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function

and after update event is
=MakePercent([Interest_Rate])
but it gives a message "syntax error"


Allen Browne said:
Change the function back to exactly the way it is here:
http://allenbrowne.com/casu-16.html
i.e. do not replace:
txt As TextBox
with:
Interest_rate
etc.

Set the AfterUpdate *property* to:
=MakePercent([Interest_Rate])
not:
[Event Procedure]

If you wish to use an event procedure, the code to use would be:
Call MakePercent(Me.[Interest_Rate])

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

senkurion said:
I have a field called interest rate in table. Data in this table is in
percenatge I used following code ( which I got from Allen Browene ansewer
to
similar qquestion in another post) I is not working for me please tell me
what is wrong with following code.

Code in module

Public Function MakePercent(Interest_rate)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named
Interest_rate to:
' =MakePercent([Interest_Rate])

If Not IsNull(Interest_rate) Then
If InStr(Interest_rate.Text, "%") = 0 Then
Interest_rate = (Interest_rate) / 100
End If
End If

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
and after update even of the text box is

=MakePercent([Interest_Rate])
but when i write this it says

expected: line number or label or statement or end of statement

i couldnot figureout waht is the problem
 
A

Allen Browne

Sounds like you are determined to use the event procedure, so use the
alternative approach:
Call MakePercent(Me.[Interest_Rate])

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

senkurion said:
Now the code in module is as below (exact copy as you said)

Public Function MakePercent(txt As TextBox)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named Text23 to:
' =MakePercent([Text23])

If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
(here i played by changing to interest_rate=interest_rate/100)
but does not work and by the way the format for the filed is %)
Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function

and after update event is
=MakePercent([Interest_Rate])
but it gives a message "syntax error"


Allen Browne said:
Change the function back to exactly the way it is here:
http://allenbrowne.com/casu-16.html
i.e. do not replace:
txt As TextBox
with:
Interest_rate
etc.

Set the AfterUpdate *property* to:
=MakePercent([Interest_Rate])
not:
[Event Procedure]

If you wish to use an event procedure, the code to use would be:
Call MakePercent(Me.[Interest_Rate])

senkurion said:
I have a field called interest rate in table. Data in this table is in
percenatge I used following code ( which I got from Allen Browene
ansewer
to
similar qquestion in another post) I is not working for me please tell
me
what is wrong with following code.

Code in module

Public Function MakePercent(Interest_rate)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named
Interest_rate to:
' =MakePercent([Interest_Rate])

If Not IsNull(Interest_rate) Then
If InStr(Interest_rate.Text, "%") = 0 Then
Interest_rate = (Interest_rate) / 100
End If
End If

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has
focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
and after update even of the text box is

=MakePercent([Interest_Rate])
but when i write this it says

expected: line number or label or statement or end of statement

i couldnot figureout waht is the problem
 
S

senkurion

"It was my mistake not to write properly actually I put
=makePercent([Interest_rate])in after update property too. it didnt work.
then I used--- Call MakePercent(Me.[Interest_Rate])in event procedure , it
didnt work either

I have your exact code in module and I named it as module 1
then I put=makePercent([Interest_rate]) in after update property

when I type 2(or any number) in Interest_rate text box it says "error 424
object required" and the typed number becomes 200.00%


Allen Browne said:
Sounds like you are determined to use the event procedure, so use the
alternative approach:
Call MakePercent(Me.[Interest_Rate])

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

senkurion said:
Now the code in module is as below (exact copy as you said)

Public Function MakePercent(txt As TextBox)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named Text23 to:
' =MakePercent([Text23])

If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
(here i played by changing to interest_rate=interest_rate/100)
but does not work and by the way the format for the filed is %)
Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function

and after update event is
=MakePercent([Interest_Rate])
but it gives a message "syntax error"


Allen Browne said:
Change the function back to exactly the way it is here:
http://allenbrowne.com/casu-16.html
i.e. do not replace:
txt As TextBox
with:
Interest_rate
etc.

Set the AfterUpdate *property* to:
=MakePercent([Interest_Rate])
not:
[Event Procedure]

If you wish to use an event procedure, the code to use would be:
Call MakePercent(Me.[Interest_Rate])

I have a field called interest rate in table. Data in this table is in
percenatge I used following code ( which I got from Allen Browene
ansewer
to
similar qquestion in another post) I is not working for me please tell
me
what is wrong with following code.

Code in module

Public Function MakePercent(Interest_rate)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named
Interest_rate to:
' =MakePercent([Interest_Rate])

If Not IsNull(Interest_rate) Then
If InStr(Interest_rate.Text, "%") = 0 Then
Interest_rate = (Interest_rate) / 100
End If
End If

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has
focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
and after update even of the text box is

=MakePercent([Interest_Rate])
but when i write this it says

expected: line number or label or statement or end of statement

i couldnot figureout waht is the problem
 
A

Allen Browne

Okay, I guess I don't understand what you are doing.

I can assure you that it does work, and I personally use it regularly. Keep
trying: I'm sure you will be able to figure it out.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

senkurion said:
"It was my mistake not to write properly actually I put
=makePercent([Interest_rate])in after update property too. it didnt work.
then I used--- Call MakePercent(Me.[Interest_Rate])in event procedure , it
didnt work either

I have your exact code in module and I named it as module 1
then I put=makePercent([Interest_rate]) in after update property

when I type 2(or any number) in Interest_rate text box it says "error 424
object required" and the typed number becomes 200.00%


Allen Browne said:
Sounds like you are determined to use the event procedure, so use the
alternative approach:
Call MakePercent(Me.[Interest_Rate])

senkurion said:
Now the code in module is as below (exact copy as you said)

Public Function MakePercent(txt As TextBox)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named Text23
to:
' =MakePercent([Text23])

If Not IsNull(txt) Then
If InStr(txt.Text, "%") = 0 Then
txt = txt / 100
End If
End If
(here i played by changing to interest_rate=interest_rate/100)
but does not work and by the way the format for the filed is %)
Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has
focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function

and after update event is
=MakePercent([Interest_Rate])
but it gives a message "syntax error"


:

Change the function back to exactly the way it is here:
http://allenbrowne.com/casu-16.html
i.e. do not replace:
txt As TextBox
with:
Interest_rate
etc.

Set the AfterUpdate *property* to:
=MakePercent([Interest_Rate])
not:
[Event Procedure]

If you wish to use an event procedure, the code to use would be:
Call MakePercent(Me.[Interest_Rate])

I have a field called interest rate in table. Data in this table is
in
percenatge I used following code ( which I got from Allen Browene
ansewer
to
similar qquestion in another post) I is not working for me please
tell
me
what is wrong with following code.

Code in module

Public Function MakePercent(Interest_rate)
On Error GoTo Err_Handler
'Purpose: Divide the value by 100 if no percent sign found.
'Usage: Set the After Update property of a text box named
Interest_rate to:
' =MakePercent([Interest_Rate])

If Not IsNull(Interest_rate) Then
If InStr(Interest_rate.Text, "%") = 0 Then
Interest_rate = (Interest_rate) / 100
End If
End If

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2185 Then 'No Text property unless control has
focus.
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
and after update even of the text box is

=MakePercent([Interest_Rate])
but when i write this it says

expected: line number or label or statement or end of statement

i couldnot figureout waht is the problem
 

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