[Modules] Updating forms'fields from module ?

G

Guest

Hi all,

I have several calculated fields (yeah, well I know it's wrong but anyway) I want to update after the 'Source Controls' changed. Well, one source fields actually updates several fields. So I wrote in the 'AfterUpDate' Event almost 30 lines to update all my calculated fields. Then I copy/pasted over the other After Update Events of my other source fields.
Then I asked myself : can't I wrote that Sub in a Module and just 'Call' it in the AfterUpDate Event ? But I didn't manage ! Access keeps not recognizing my Sub.
What are the points I missed ? Or the procedure I should follow ?

To be more precise, I wrote something like this :

in my txtSourceField1, in the AfterUpdate Event :
form![frm FormName]![txtCalculatedField1]= blah blah 'which worked

then I copy/pasted it to a 'mod General' Module, creating an 'UpdateCalculatedFields' Sub, containing the same code. In the AfterUpdate Event, I put something like :
Call UpdateCalculatedFields() 'which didn't work !

Any Help Would be apreciated !

Nico
 
K

Katrina

In the module, did you create the sub as a function?

It has to be a function

Function UpdateCalculatedfields()
blah blah
blah blah blah
end function


HTH
Kat

Nico said:
Hi all,

I have several calculated fields (yeah, well I know it's wrong but anyway)
I want to update after the 'Source Controls' changed. Well, one source
fields actually updates several fields. So I wrote in the 'AfterUpDate'
Event almost 30 lines to update all my calculated fields. Then I copy/pasted
over the other After Update Events of my other source fields.
Then I asked myself : can't I wrote that Sub in a Module and just 'Call'
it in the AfterUpDate Event ? But I didn't manage ! Access keeps not
recognizing my Sub.
What are the points I missed ? Or the procedure I should follow ?

To be more precise, I wrote something like this :

in my txtSourceField1, in the AfterUpdate Event :
form![frm FormName]![txtCalculatedField1]= blah blah 'which worked

then I copy/pasted it to a 'mod General' Module, creating an
'UpdateCalculatedFields' Sub, containing the same code. In the AfterUpdate
Event, I put something like :
 
D

Dirk Goldgar

Katrina said:
In the module, did you create the sub as a function?

It has to be a function

Function UpdateCalculatedfields()
blah blah
blah blah blah
end function

It only has to be a function if it will be called directly from the
AfterUpdate property as an expression; e.g.,

=UpdateCalculatedFields()

It sounds to me as though Nico is calling UpdateCalculatedFields() from
an event procedure, though of course I could be wrong.
 
G

Guest

Hi Katrina and Dirk,

Yes indeed I tryed using a Function, declaring it As a Boolean, since I think it doesn't matter. Actually, I guess a Sub is kinda a Function which returns a Void. Then in the Event, I declared a private boolean which takes the value of my function, but didn't work too.
Access puts a MsgBox when it's supposed to update my fields, saying it doesn't recognize the user function or macro.
I guess I am missing a point in the links between my Class Object Form and my Module.

Here is my event:
Private Sub txtSourceField_AfterUpdate()

Call UpdateCalculatedFields

End Sub

and the Sub in my Module :

Public Sub UpdateCalculatedFields()

forms![frm myForm]![txtCalculatedField1] = blah blah..
End Sub

Any clue ?
Thanks
 
G

Guest

Well, nevermind :)

I copyed my forms, well, all my fields, and put the code back in order, and it worked !
Just called my public Sub in my event...
It's a mystery !

Thanks for your help !

See ya around !
Nico
 
D

Dirk Goldgar

Nico said:
Well, nevermind :)

I copyed my forms, well, all my fields, and put the code back in
order, and it worked !
Just called my public Sub in my event...
It's a mystery !

Thanks for your help !

See ya around !
Nico

Possibly the event property line for the control wasn't set to "[Event
Property]"? Pasting the event procedure back into the form's module
would probably reset that property.
 

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