victorpeters
IS-IT--Management
Hi,
I have a form/sub-form. On the main form the user selects a record, and then clicks a command button which will insert fifteen new records in the related table which is displayed by the sub-form. The user can then edit those fifteen rows in the subform in order to provide additional data.
This all works fine, except I can not get the subform to refresh after the new records are added by the command button. The records are definitely being added to the table. The subform does correctly display the data if the user forces the subform to refresh either by pressing F9 or by going to the next record and then returning to the current record. But I can get the subform to automatically refresh from my code.
I have read a lot of forum posts on this issue and tried many different proposed solutions. I have called ReQuery on the sub-form, and Refresh on the subform. I even tried called Requery on the master form. I even tried calling Repaint on the subform. Nothing works!
I hope one of you can tell me what I'm doing or if there is a bug in Access. Here is the key part of my code from my command button:
'Add the new data to the related table (this works)
cn.BeginTrans
Do While Not rs.EOF
cmd.CommandText = "INSERT INTO [Survey Responses]... cmd.Execute
rs.MoveNext
Loop
cn.CommitTrans
'Alter the subform RecordSource to only display the new records (this works, if it will refresh)
Me.Survey_Responses_subform.Form.RecordSource = "SELECT [Survey Responses].[Schedule ID].....
'Attempting to refresh the subform
Me.Survey_Responses_subform.Form.Requery
Me.Survey_Responses_subform.Form.Refresh
Thanks in advance for your help! Let me know if you need additional information.
Victor
I have a form/sub-form. On the main form the user selects a record, and then clicks a command button which will insert fifteen new records in the related table which is displayed by the sub-form. The user can then edit those fifteen rows in the subform in order to provide additional data.
This all works fine, except I can not get the subform to refresh after the new records are added by the command button. The records are definitely being added to the table. The subform does correctly display the data if the user forces the subform to refresh either by pressing F9 or by going to the next record and then returning to the current record. But I can get the subform to automatically refresh from my code.
I have read a lot of forum posts on this issue and tried many different proposed solutions. I have called ReQuery on the sub-form, and Refresh on the subform. I even tried called Requery on the master form. I even tried calling Repaint on the subform. Nothing works!
I hope one of you can tell me what I'm doing or if there is a bug in Access. Here is the key part of my code from my command button:
'Add the new data to the related table (this works)
cn.BeginTrans
Do While Not rs.EOF
cmd.CommandText = "INSERT INTO [Survey Responses]... cmd.Execute
rs.MoveNext
Loop
cn.CommitTrans
'Alter the subform RecordSource to only display the new records (this works, if it will refresh)
Me.Survey_Responses_subform.Form.RecordSource = "SELECT [Survey Responses].[Schedule ID].....
'Attempting to refresh the subform
Me.Survey_Responses_subform.Form.Requery
Me.Survey_Responses_subform.Form.Refresh
Thanks in advance for your help! Let me know if you need additional information.
Victor