Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to contol Events order

Status
Not open for further replies.

AndreAraujo

Programmer
Feb 14, 2002
62
0
0
PT
Thanks for taking time to read this. My application has one main form with a sub form on it. When i add a new record in the main form using the code;
Private Sub cmdAdd_Click()
Dim Rst As Recordset
Set Rst = Me.Recordset
Rst.AddNew
'**********************
me.Num = NovaOrdem()
Rst.Update
Rst.Close
Set Rst = Nothing
End sub

The event On Current of the sub Form is activated after the command RST.addnew and before i get the vale for me.Num, then i get a error because the num value is used in the Sub Form On current event.

Can i force the on current event of the sub to wait for the generation of the Num value??

André

 
no, there is no way to change the built-in order of the access events. what you can do is make use of that order when sequencing you code so all prerequisites are filled, and create functions that explicitly lay out the order of steps. if you know where the value for "num" comes from you might try using the source value rather than num itself. if this isn't possible you'll probably have move your code around to different event steps (there are plenty of them) attached to the same or similar user actions.
 
Andre,

You are using the recordset that is bound to the form. I cannot help but wonder if it were not better to use the

DoCmd.GoToRecord , , acNewRec

That notwithstanding, to make your code work, move the

me.Num = NovaOrdem()

after the update.


Rollie E
 

The problem is that the num is the code for the new record, and the sub form needs that code to run a query that sees if the sub order exists and the on current event is used to
mark the sub record when i move across the records

I tried the event Before update or Before insert in the Main Form but they occurs after the on current in the sub form.

Any ideas????

Andre
 
Where does 'num' come from? Is it not an autonumber for the new record.


Rollie E
 
Hello Rollie
No the Num is not an autonumber it's calculated.
Andre
 
If you would like me to look at it, send a zipped copy of a sample to

rollie@bwsys.net
 
Hi Rollie, I fix the problem the default value of the text box set to 0, it working , Thanks for the advices.

Andre
 
Rolliee,

It's best to deal with these things on the forum. It helps others learn, and that's why the forums exist--so the whole community of developers can learn.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top