thebatfink
Registered User.
- Local time
- Today, 09:37
- Joined
- Oct 2, 2008
- Messages
- 33
Hi, I have a Mainform with two sub forms which displays information from two tables with a 1 to many relationship. The sub forms show the data from the many side of this relationship. The sub form is within a tab control.
Basically the first sub form has a single text boxes for each field in the table so one record can be viewed or input at a time, and the second sub form shows a datasheet view of all the records in the many side relating to the 1 side.
When editing a record, I didn't want to do this in the datasheet view so I added 'previous' and 'next' buttons to my subform with the text fields so the user could cycle through them until they found the one they wanted to edit. The datasheet subform was just to give an at a glance overview..
Here is the code for the cycle button
The problem I have is if I open the main form, immediately click the tab control which contains the sub forms, the first sub form populates with the first record, the datasheet view sub form populates with all the records, but if I click the 'Next' 'Previous' buttons, nothing happens.
I checked and this is because Me.Recordset.RecordCount is returning 1, and not the total records that are related.
To correct this, if I click on the datasheet sub form, then click the 'Next' 'Previous' buttons, it works and Me.Recordset.RecordCount returns the correct number.
So my question, could any one explain the reason for this behaviour to me and how I would go about applying a remedy to it?
Thanks!!
Basically the first sub form has a single text boxes for each field in the table so one record can be viewed or input at a time, and the second sub form shows a datasheet view of all the records in the many side relating to the 1 side.
When editing a record, I didn't want to do this in the datasheet view so I added 'previous' and 'next' buttons to my subform with the text fields so the user could cycle through them until they found the one they wanted to edit. The datasheet subform was just to give an at a glance overview..
Here is the code for the cycle button
Code:
Private Sub QADataNewNextButton_Click()
On Error GoTo Err
DoCmd.SetWarnings False
If Me.CurrentRecord < Me.Recordset.RecordCount Then
DoCmd.GoToRecord , , acNext
End If
Me.Refresh
DoCmd.SetWarnings True
Exit Sub
Err:
DoCmd.SetWarnings True
MsgBox Err.Description
End Sub
The problem I have is if I open the main form, immediately click the tab control which contains the sub forms, the first sub form populates with the first record, the datasheet view sub form populates with all the records, but if I click the 'Next' 'Previous' buttons, nothing happens.
I checked and this is because Me.Recordset.RecordCount is returning 1, and not the total records that are related.
To correct this, if I click on the datasheet sub form, then click the 'Next' 'Previous' buttons, it works and Me.Recordset.RecordCount returns the correct number.
So my question, could any one explain the reason for this behaviour to me and how I would go about applying a remedy to it?
Thanks!!