If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Saving a record in subform
Hi,
I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
#2
|
|||
|
|||
Saving a record in subform
Do both forms have a table or query as their record source?
Are you using the link master and link child fields? If you are using bound forms, does your save button have code like this? If Me.Dirty = True Then Me.Dirty = False End If Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Hi, I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
#3
|
|||
|
|||
Saving a record in subform
Yes both forms have a table as their record source and they are
linked. I am using the wizard provided save command, so no I don't have that code. I am not sure where this is going. On Dec 8, 2:28*am, "Jeanette Cunningham" wrote: Do both forms have a table or query as their record source? Are you using the link master and link child fields? If you are using bound forms, does your save button have code like this? If Me.Dirty = True Then * * Me.Dirty = False End If Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Hi, I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. *Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. *I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
#4
|
|||
|
|||
Saving a record in subform
Thanks for providing the info.
When you are using bound forms and main form and subform are linked using the link master and link child fields, access does save the subform record when user clicks out of the subform onto the main form. I sugest that you remove the save button from the subform - as access will automatically save the subform data when user clicks something on the main form. Put an unbound textbox on the subform and set its control source to =Sum([FieldName]) To check for a match when on the main form, you can use code like this-- Private Function CheckForMatch() As Boolean If Me.[NameOfControl] = Me.[SubformControlName].Form.[NameOf TheUnboundTextBox] Then CheckForMatch = True Else CheckForMatch = False End If End Function Then on the unload event for the main form, you can go If Not CheckForMatch = True Then Cancel = True End If The above should prevent the main form closing unless the numbers match. Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Yes both forms have a table as their record source and they are linked. I am using the wizard provided save command, so no I don't have that code. I am not sure where this is going. On Dec 8, 2:28 am, "Jeanette Cunningham" wrote: Do both forms have a table or query as their record source? Are you using the link master and link child fields? If you are using bound forms, does your save button have code like this? If Me.Dirty = True Then Me.Dirty = False End If Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Hi, I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
#5
|
|||
|
|||
Saving a record in subform
I had code very similar to this checking for a match (your code is
better though). My problem is that if they enter the number in the control of the subform and try to close the form without first exiting that control, the sum does not update before trying to close. This would only be a problem if the control in the subform is the very last control the user enters a value. On Dec 8, 2:32*pm, "Jeanette Cunningham" wrote: Thanks for providing the info. When you are using bound forms and main form and subform are linked using the link master and link child fields, access does save the subform record when user clicks out of the subform onto the main form. I sugest that you remove the save button from the subform - as access will automatically save the subform data when user clicks something on the main form. Put an unbound textbox on the subform and set its control source to =Sum([FieldName]) To check for a match when on the main form, you can use code like this-- Private Function CheckForMatch() As Boolean If Me.[NameOfControl] = Me.[SubformControlName].Form.[NameOf TheUnboundTextBox] Then * * CheckForMatch = True Else * * CheckForMatch = False End If End Function Then on the unload event for the main form, you can go If Not CheckForMatch = True Then * * Cancel = True End If The above should prevent the main form closing unless the numbers match. Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Yes both forms have a table as their record source and they are linked. I am using the wizard provided save command, so no I don't have that code. I am not sure where this is going. On Dec 8, 2:28 am, "Jeanette Cunningham" wrote: Do both forms have a table or query as their record source? Are you using the link master and link child fields? If you are using bound forms, does your save button have code like this? If Me.Dirty = True Then Me.Dirty = False End If Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message .... Hi, I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
#6
|
|||
|
|||
Saving a record in subform
You can also use recalc like this--
Me.Recalc You could try using recalc on the subform in its after update event. Access gives a lower priority to doing sums than running much of the form's code. Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... I had code very similar to this checking for a match (your code is better though). My problem is that if they enter the number in the control of the subform and try to close the form without first exiting that control, the sum does not update before trying to close. This would only be a problem if the control in the subform is the very last control the user enters a value. On Dec 8, 2:32 pm, "Jeanette Cunningham" wrote: Thanks for providing the info. When you are using bound forms and main form and subform are linked using the link master and link child fields, access does save the subform record when user clicks out of the subform onto the main form. I sugest that you remove the save button from the subform - as access will automatically save the subform data when user clicks something on the main form. Put an unbound textbox on the subform and set its control source to =Sum([FieldName]) To check for a match when on the main form, you can use code like this-- Private Function CheckForMatch() As Boolean If Me.[NameOfControl] = Me.[SubformControlName].Form.[NameOf TheUnboundTextBox] Then CheckForMatch = True Else CheckForMatch = False End If End Function Then on the unload event for the main form, you can go If Not CheckForMatch = True Then Cancel = True End If The above should prevent the main form closing unless the numbers match. Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Yes both forms have a table as their record source and they are linked. I am using the wizard provided save command, so no I don't have that code. I am not sure where this is going. On Dec 8, 2:28 am, "Jeanette Cunningham" wrote: Do both forms have a table or query as their record source? Are you using the link master and link child fields? If you are using bound forms, does your save button have code like this? If Me.Dirty = True Then Me.Dirty = False End If Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia "hotplate" wrote in message ... Hi, I need to save a record in a subform before trying to close the main form. I tried creating a save command in the subform and calling it when trying to close the main form. Unfortunately I could not figure out how to do this. The reason I need to save subform record is because I am adding the numbers in the subform to see if they equal a number in the main record, if they don't match the form will not close. I can't even check for a match if the subform record does not get saved before closing. I am using a command button to close the main form. Thanks |
Thread Tools | |
Display Modes | |
|
|