D
David
I'm having a number of issues with split forms in Access 2007, mostly around
adding new records coupled with code running in the form_current event.
If I start adding a new record (in either the split form or form parts of
the form) and then move to a new record, I get duplicate rows and incorrect
rows showing at the bottom of the split form. It's like it gets out of sync
and the display is incorrect. If I then close and reopen the form, the data
is OK and the form displays correctly.
This seems to be caused by some code I have which runs when the form_current
method is called. If I disable it, everything seems fine. But I can't see
for the life of me why it won't work.
Here is the code:
Private Sub UpdateStatusBar()
'This routine updates the contents of the status bar with the list of
attributes for this person.
Dim dbsPJ As DAO.Database
Dim QD1 As QueryDef
Dim rstAttributes As DAO.Recordset
Dim intAnswer As Integer
Dim strStatus As String
On Error GoTo ErrorHandler
'Check we're not adding a record.
If Me.NewRecord Then
'The user is adding a record, so just set to status bar to blank and
exit.
Forms!PersonalDetails.txtStatus.Value = ""
Exit Sub
End If
' Get attributes for this person.
Set dbsPJ = CurrentDb
Set QD1 = dbsPJ.QueryDefs!RetrieveAttributesQuery
'QD1.Parameters!PersonalIDParameter = txtPersonalID.Value
QD1.Parameters!PersonalIDParameter = Me.Recordset!PersonalID
Set rstAttributes = QD1.OpenRecordset
'Display attributes in status bar.
strStatus = ""
Do Until rstAttributes.EOF
strStatus = strStatus + rstAttributes!PersonalAttributeDescription +
" "
rstAttributes.MoveNext
Loop
Forms!PersonalDetails.txtStatus.Value = strStatus
'Cleanup
rstAttributes.Close
dbsPJ.Close
Set rstAttributes = Nothing
Set dbsPJ = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
The form contains details about individuals. Name, address etc. The idea
is that a status bar at the bottom of the form is updated with each cutomer's
'attributes'. These are stored in a table called 'PersonalAttributes' and the
query above just grabs the attributes for the customer, and builds a string
with them e.g. "Volunteer Board Member". A text box control at the bottom of
the form is then updated with this string.
Can anyone help?
Thanks very much
David
adding new records coupled with code running in the form_current event.
If I start adding a new record (in either the split form or form parts of
the form) and then move to a new record, I get duplicate rows and incorrect
rows showing at the bottom of the split form. It's like it gets out of sync
and the display is incorrect. If I then close and reopen the form, the data
is OK and the form displays correctly.
This seems to be caused by some code I have which runs when the form_current
method is called. If I disable it, everything seems fine. But I can't see
for the life of me why it won't work.
Here is the code:
Private Sub UpdateStatusBar()
'This routine updates the contents of the status bar with the list of
attributes for this person.
Dim dbsPJ As DAO.Database
Dim QD1 As QueryDef
Dim rstAttributes As DAO.Recordset
Dim intAnswer As Integer
Dim strStatus As String
On Error GoTo ErrorHandler
'Check we're not adding a record.
If Me.NewRecord Then
'The user is adding a record, so just set to status bar to blank and
exit.
Forms!PersonalDetails.txtStatus.Value = ""
Exit Sub
End If
' Get attributes for this person.
Set dbsPJ = CurrentDb
Set QD1 = dbsPJ.QueryDefs!RetrieveAttributesQuery
'QD1.Parameters!PersonalIDParameter = txtPersonalID.Value
QD1.Parameters!PersonalIDParameter = Me.Recordset!PersonalID
Set rstAttributes = QD1.OpenRecordset
'Display attributes in status bar.
strStatus = ""
Do Until rstAttributes.EOF
strStatus = strStatus + rstAttributes!PersonalAttributeDescription +
" "
rstAttributes.MoveNext
Loop
Forms!PersonalDetails.txtStatus.Value = strStatus
'Cleanup
rstAttributes.Close
dbsPJ.Close
Set rstAttributes = Nothing
Set dbsPJ = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
The form contains details about individuals. Name, address etc. The idea
is that a status bar at the bottom of the form is updated with each cutomer's
'attributes'. These are stored in a table called 'PersonalAttributes' and the
query above just grabs the attributes for the customer, and builds a string
with them e.g. "Volunteer Board Member". A text box control at the bottom of
the form is then updated with this string.
Can anyone help?
Thanks very much
David