This should be simple, right?

jazztie

Registered User.
Local time
Today, 01:23
Joined
Jun 9, 2005
Messages
19
I'm completely lost... I don't understand the logic of Access.

What I want to do is update a value in a form when another value is changed.

What I have now is:
"Value" - onChange - run macro "25Procent"

This macro does:
SetValue
Item: [Forms]![Tarife]![Value25]
Expression: [Forms]![Tarife]![Value]*1,25

But I always get an error. When I run it in the macro window it reads 'Out of string space' (what does this mean???) ... when I run it in the form window -- it errors as well.

What am I doing wrong? Both values have the same format (euro) --- both have Control Source's from the database (resp. Value and Value25) ... that shouldn't matter, right?

any help is appreciated!
Jazz
 
It might be the ONCHANGE Event, try the LOST FOCUS event first.

If that doesn't work try this.
Expression: val([Forms]![Tarife]![Value]) *1,25

I wonder if it thinks the value is a string instead of a numeric
 
get rid of the macro and us VB code, then enter the following on the AfterUpdate event of the control you are checking if it changed.

This code can be used if the control you want to change is in the same form. If it is not, then change the me, to Forms!Masterform.Subform!Form.txtResults, where MasterForm is the name of your main form and Subform is the name of your subform.

Sub myControl_AfterUpdate()
Dim PercentValue as integer

'Converts the value in the text box to Interger and multiplies it by 0.25, the value is stored on a temporary variable called PercentValue.
PercentValue = Cint(me.txtboxwithoriginalvalue) * 0.25

'Writes the resulst in a text box called txtResults after it converts the interger value in the PercentValue variable back to a string. This is necessary in order to wrte the value back to a text box since text boxes store strings
me.txtResults = Cstr(PercentValue)
End Sub
 
Hi Godofhell,

It seemed very logic to me... and it also is, but I still get an error:
Code:
The expression After Update you entered as the event property setting produced the following error: A problem occured while Microsucks Access was communicating with the OLE server or ActiveX control. 
* The expression may not result in the name of a macro, the name of a user defined function or [Event Procedure]
* There may have been an error evaluating the function, event, or macro
I'm lost here... what happened? And why does it produce an error?

I entered the VB code exactly as you posted it (checked the names of the variables of course)... so.... :confused:

Jazz
 
How about...

Private Sub myControl_AfterUpdate() 'AfterUpdate event of item changed

Dim MyPercentValue as Double 'Make sure your variable name isn't a reserve word

MyPercentValue = Me.txtboxwithoriginalvalue.text * 0.25

'If your me.txtboxwithoriginalvalue is a string or has a text property then you would use..

MyPercentValue = Val(me.txtboxwithoriginalvalue.text) * 0.25

'Assign new value to the textbox you want changed.

me.txtResults.text = MyPercentValue

MyPercentValue = Nothing 'Release the value of MyPercentValue

End Sub



Click on the item you want to create the AfterUpdate event on in design view.
Properties
Events
AfterUpdate
...
CodeBuilder

Insert and write your code.

Sometimes when you manually create your AfterUpdate event or any event of your component in the IDE editor, it wont associate it with the control.
You have to go back and go through the properties of the control to assign the event to be fired.

Another thing to start using is inserting a "breakpoint" and step through your code using F8. This is usually a good idea to see if the event is actually fired and when you step through your code you can "hover" your mouse over items in your code to see their assigned value and how or whether the value changes.

I still have to remind myself to do this.
Sometimes Access will not throw an error when running the code, but if you throw in a breakpoint and step through it, Access will sometimes give you an error where otherwise it wont. So it is a good thing to check.

Hope this helps.
 
Last edited:
This is just NUTS!!! :eek: :mad: :(

I still get the same error from Access. This is the code I have:
Code:
Private Sub Arbeitszeit_AfterUpdate()
    Dim MyPercentValue As Double
     
    MyPercentValue = CInt(Me.Arbeitszeit.Text) * 1.25

    Me.Arbeitszeit25.Text = MyPercentValue
End Sub

And, again (getting frustrated here), I get the error I posted before.
"The expression After Update you entered as the event property setting produced the following error: A problem occured while MS Access was communicating with the OLE server or ActiveX control.
* The expression may not result in the name of a macro, the name of user-defined function, or [Event Procedure]
* There may have been an error evaluating the function, macro, or event"

Now, I also tried it with different variable names (posting those fields on the form) -- same error
Releasing the MyPercentValue-variable -- same error
Using VAL instead of Cint -- same error

Basically: I DON'T UNDERSTAND!! ... what's going on here? Please, could anyone tell me??
 
try:-

Private Sub Arbeitszeit_AfterUpdate()
Me.Arbeitszeit25 = Me.Arbeitszeit * 1.25
End Sub

HTH

Peter
 
Nope, -- same error...

What about this error? Can anyone explain me what it means? I'm starting to think something else is wrong, I mean, all these examples I've tried -- all of them giving the same error... that's not logical, is it?

:(
Jazz
 
The error generaly means that you have the name of the controll wrong, but with a thing this simple I cant see it's that so presumably some thing else.
I would try making a copy of the form and in the copy delete all but Arbeitszeit and Arbeitszeit25 and get rid of any other links to macros that may be in the form. then test it. If you still get the error then try creating a new form from scratch and add the controlls and see what happens then. If you don't get the error on the copy then it must be some other controll causing the error, and I'm afraid it is down to trial and error to pin it down.

HTH

Peter
 
hi did you get anywhere with this problem? I have exactly the same problem trying to use setvalue via a macro on an access form.
 

Users who are viewing this thread

Back
Top Bottom