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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

The percentage format of a field when creating a table



 
 
Thread Tools Display Modes
  #1  
Old June 7th, 2004, 01:56 PM
Peter Max
external usenet poster
 
Posts: n/a
Default The percentage format of a field when creating a table

I'm trying to achieve the same thing on a form, but no satisfaction so far. Firstly, what goes on the front of =MakePercent([MyRate]), to avoid a compile error? If I give it the name of the field in the source table, it compiles. But when I pass a value through the function module, it comes out wrong.

This is my AfterUpdate procedure attached to the input text box on the form:

Private Sub ctlProjectPerCent_AfterUpdate()
ProjectPerCent = MakePerCent([ctlProjectPerCent])
Stop
End Sub

And this is the module procedu

Public Function MakePerCent(ctl As Control)
If InStr(ctl.Text, "%") = 0 Then
ctl = ctl / 100
End If
End Function

If I type 20 in the text box on the form, I expect to get 20% back. I get 20 going through to the MakePerCent function, converting to 0.02 at the end of the function. But it is passed back to the AfterUpdate procedure as 0, and it comes out as 2000.00% in the text box (which suggests that the value hasn't been passed back.

It's a while since I did any VBA in Access, so I've probably made a stupid mistake somewhere. Any ideas?
  #2  
Old June 7th, 2004, 02:35 PM
Van T. Dinh
external usenet poster
 
Posts: n/a
Default The percentage format of a field when creating a table

I am not sure of your set-up but there are a few problems with the posted
code:

1. You haven't declared the returned data type for your function
MakePerCent() which means that it will return a Variant by default. Use
strong typing whenever possible. This is not the problem, though.

2. You haven't assigned a returned *value* for the function either so the
function will *always* return Null regardless of what is in the Control.
Hence, I am not sure what you are trying to do with the function.

3. I think the statement "Stop" is not appropriate as used normally.

Check Access Help on the user-defined function and the Stop statement.

--
HTH
Van T. Dinh
MVP (Access)




"Peter Max" wrote in message
...
I'm trying to achieve the same thing on a form, but no satisfaction so

far. Firstly, what goes on the front of =MakePercent([MyRate]), to avoid a
compile error? If I give it the name of the field in the source table, it
compiles. But when I pass a value through the function module, it comes out
wrong.

This is my AfterUpdate procedure attached to the input text box on the

form:

Private Sub ctlProjectPerCent_AfterUpdate()
ProjectPerCent = MakePerCent([ctlProjectPerCent])
Stop
End Sub

And this is the module procedu

Public Function MakePerCent(ctl As Control)
If InStr(ctl.Text, "%") = 0 Then
ctl = ctl / 100
End If
End Function

If I type 20 in the text box on the form, I expect to get 20% back. I get

20 going through to the MakePerCent function, converting to 0.02 at the end
of the function. But it is passed back to the AfterUpdate procedure as 0,
and it comes out as 2000.00% in the text box (which suggests that the value
hasn't been passed back.

It's a while since I did any VBA in Access, so I've probably made a stupid

mistake somewhere. Any ideas?


 




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 01:15 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.