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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform problem...always saves

Status
Not open for further replies.

btj

Technical User
Nov 17, 2001
94
US
I have a subform bound to a main form by a field called Category. The combo box which holds Category is the only item on the main form.

The subform is set up as a datasheet and displays 6 fields of information. The format (datasheet) is such because users may need to go in and change one field for every record (i.e from Pass to Fail).

While testing the database, I noticed that the records on the subform save as soon as they lose focus. As users are updating multiple fields at a time, I want to prevent or delay saving until the user is done (i.e. OnClick - save).

Does anyone have ideas on how I can do this. I would appreciate any help as I am stumped!

- Ben
 
I don t know if you can do that. What you can do is use transaction. I not remember the synthax but you begin a transaction (can be on lost focus of the category list) and if all is ok, do commitTrans to save changes or rollbackTrans to cancel the changes (ex on ok/cancel button click).

Hope it help!
Phil
 
Phil,
That was a great help! I will try to read up about Transactions as I had not heard of them before now.

From my initial reading, most examples seemed geared towards doing mass changes automatically rather than what I need. Hopefully, I will be able to figure this out. Should you have any additional advice, I would appreciate it.

Thanks again...
 
This is the code i ever user in a program for button ok, cancel and apply with the transaction (but in french) :

Private Sub Form_Load()
Set cnn = Application.CurrentProject.Connection
cnn.BeginTrans;
End Sub

Private Sub cmdAnnuler_Click()
Dim sReponse As String
If intRafraichirEnCours = 0 Then
sReponse = MsgBox("Vous allez annuler les dernières modifications. Êtes-vous sûr(e) de vouloir continuer ?", vbExclamation + vbYesNo, "Annuler les modifications")
If sReponse = vbYes Then
cnn.RollbackTrans
Me.Undo
DoCmd.Close
End If
Else
DoCmd.Close
End If
End Sub

Private Sub cmdAppliquer_Click()
cnn.CommitTrans
cnn.BeginTrans
cmdOk.SetFocus
End Sub

Private Sub cmdOk_Click()
Dim sReponse As String
If intRafraichirEnCours = 0 Then
sReponse = MsgBox("Voulez-vous enregistrer les modifications ?", vbExclamation + vbYesNo, "Enregistrement des vols")
If sReponse = vbYes Then
cnn.CommitTrans
intRafraichirEnCours = 0
activeDesactiveBoutons (Me.Name)
DoCmd.Close
End If
Else
DoCmd.Close
End If
End Sub

I think it will help you! :)

Phil
 
You can do what you want using ADO. There is an example of how to handle batch updates in a book by Rob Macdonald called Seriou ADO. It is too much to try and explain in this form. I got a copy off of Amazon.com where you can read a description about the book.
 
Thank you both for your responses. Phil - I will try your code out today. cmmrfrds - I will look into that book to see if it addresses my issue.

Let me try a follow-up question...as a subform saves as soon as its focus is lost, is there any way in which I can still have command buttons (i.e. Cancel and Close) reside in the Main form but still operate within the sub?

Thanks again for all of your help.

- Ben

 
The transaction is on the connection, it works for the main form and the sub form at the same time.

Phil
 
Phil - thanks, again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top