Closing and re-opening forms on exit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any method that when i exit a field on a form, that i canon the exit
button tell the form to close and automatically reopen again.
I use an "Udate" command in the form, and i need to write the date before i
go to the start of the form again
 
Is there any method that when i exit a field on a form, that i canon the exit
button tell the form to close and automatically reopen again.
I use an "Udate" command in the form, and i need to write the date before i
go to the start of the form again

You don't need to close then re-open the form just to save the data.
Code a command button:

DoCmd.RunCommand acDmdSaveRecord
 
Hi Fredg
I inserted the code as required, but it still didn't update the record, I
have posted the code, if you can have a quick look as i must be doing
something wrong.



Private Sub QTY_Exit(Cancel As Integer)
If Me.JobnumbersID = 11041 Then
Me.tempqty = Me.QuantityInStock + Me.QTY
Me.QuantityInStock = Me.tempqty
DoCmd.RunSQL "UPDATE[stock] set [quantityinstock]=" & Me.QuantityInStock
& " where [stocknumberID]=" & Me.StockNumberID
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdSaveRecord
Else: Me.tempqty = Me.QuantityInStock - Me.QTY
QuantityInStock = Me.tempqty
DoCmd.RunSQL "UPDATE[stock] set [quantityinstock]=" &
Me.QuantityInStock & " where [stocknumberID]=" & Me.StockNumberID
Me.tempqty = 0
DoCmd.RunCommand acCmdSaveRecord
End If
Me.tempqty = 0
DoCmd.RunCommand acCmdSaveRecord
End Sub
 
You don't need to close then re-open the form just to save the data.
Code a command button:

DoCmd.RunCommand acDmdSaveRecord

tiny typo: acCmdSaveRecord.

An alternative syntax to save the record is

If Me.Dirty Then Me.Dirty = False

John W. Vinson [MVP]
 
I tried both these methods and it did not write the data back to the file,
When i go the the next add record the quantity has not been written to, it
only appears to write it when i exit the form and re-enter the form. Then the
data is written
to the file
 
I am sorry i mislead everyone on my problem, The data is been written to the
file, but unless i close the form and re-open the form, the updated data is
not correct. EG if i add 200 of item 10605 the total changed to 800, and if
i then re-enter more data the total stayes at 600 not the updated amount of
800. So what i really need to do is refresh the data each time i finish
entering datat in a form, before i enter the next lot of data into the form
 
I am sorry i mislead everyone on my problem, The data is been written to the
file, but unless i close the form and re-open the form, the updated data is
not correct. EG if i add 200 of item 10605 the total changed to 800, and if
i then re-enter more data the total stayes at 600 not the updated amount of
800. So what i really need to do is refresh the data each time i finish
entering datat in a form, before i enter the next lot of data into the form

This isn't making sense. What is the Recordsource for the form? Are you doing
calculations in the form? If so, how? what expressions? What are the Control
Sources for the totals fields?

John W. Vinson [MVP]
 
It seems to me that if you add the following to John Vinson's post it might
do what you want.

after
If Me.Dirty Then Me.Dirty = False
add
Me.Requery

This will cause the form to refresh with the current data.

HTH

Steve
 
It seems to me that if you add the following to John Vinson's post it might
do what you want.

after
If Me.Dirty Then Me.Dirty = False
add
Me.Requery

This will cause the form to refresh with the current data.

HTH

Thanks Steve! You're very likely correct.

John W. Vinson [MVP]
 

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

Back
Top