Stranger and stranger. I can not imagine how the
RecordCount property can be Null. I am beginning to
seriously suspect some kind of corruption and suggest that
you make a backup copy of the mdb file before it gets any
worse. Then create a new, blank mdb, set all the options
appropriately (especially Name Autocorrect off) and then
import everthing from the problem mdb.
I did as you suggested but was still getting the same errors. But, I've
finally got everything working. A better programmer could come up with
a more elegant solution, but this is working without any performance
problems. Here's what I did:
---------------------------------------------------------------------
The Current event of the main form (frmPatients)
---------------------------------------------------------------------
Private Sub Form_Current()
If IsNull(Me.PatientID) Then
' On a new patient, hide all the visit text boxes on the
referral subform.
Me!frmReferrals.Form!txtVisit1.Visible = False
Me!frmReferrals.Form!txtVisit2.Visible = False
Me!frmReferrals.Form!txtVisit3.Visible = False
Me!frmReferrals.Form!txtVisit4.Visible = False
Else
' Otherwise, run the referral subform's Load event
Me.frmReferrals.SetFocus ' this was still needed, even after
reimporting eveything
Me.frmReferrals.Form.Form_Load
End If
End Sub
----------------------------------------------------------------
The Load event of the subform (frmReferrals)
----------------------------------------------------------------
Public Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF Or .AbsolutePosition >= 4
Me("txtVisit" & .AbsolutePosition + 1).Visible =
True
Me("txtVisit" & .AbsolutePosition + 1) =
!ReferralDate
.MoveNext
Loop
End If
End With
' Show/hide the visit text boxes based on how many referrals the
patient has
If DCount("ReferralID", "tblReferrals", "[PatientID] = " & _
Forms!frmPatients!PatientID) = 1 Then
Me.txtVisit1.Visible = True
Me.txtVisit2.Visible = False
Me.txtVisit3.Visible = False
Me.txtVisit4.Visible = False
ElseIf DCount("ReferralID", "tblReferrals", "[PatientID] = " & _
Forms!frmPatients!PatientID) = 2 Then
Me.txtVisit1.Visible = True
Me.txtVisit2.Visible = True
Me.txtVisit3.Visible = False
Me.txtVisit4.Visible = False
' etc. for each referral up to 4
End If
End Sub
-------------------------------------------------------------------
The Current event of the subform (frmReferrals)
-------------------------------------------------------------------
Private Sub Form_Current()
If IsNull(Me.ReferralID) Then
' If this is a new referral, do nothing
Else
' Otherwise, show/hide the visit text boxes based
' on how many referrals the patient has
If DCount("ReferralID", "tblReferrals", "[PatientID] = " & _
Forms!frmPatients!PatientID) = 1 Then
Me.txtVisit1.Visible = True
Me.txtVisit2.Visible = False
Me.txtVisit3.Visible = False
Me.txtVisit4.Visible = False
ElseIf DCount("ReferralID", "tblReferrals", "[PatientID] = " &
_
Forms!frmPatients!PatientID) = 2 Then
Me.txtVisit1.Visible = True
Me.txtVisit2.Visible = True
Me.txtVisit3.Visible = False
Me.txtVisit4.Visible = False
'etc. for each referral up to 4
End If
End If
I also call the subform's Load event in its AfterUpdate event, as well
as after a user clicks a Delete button to delete the record. This way,
the visit text boxes are updated when a new referral is added or
deleted.
Thanks again for all your help.
Kurt
Marshall said:
Stranger and stranger. I can not imagine how the
RecordCount property can be Null. I am beginning to
seriously suspect some kind of corruption and suggest that
you make a backup copy of the mdb file before it gets any
worse. Then create a new, blank mdb, set all the options
appropriately (especially Name Autocorrect off) and then
import everthing from the problem mdb.
--
Marsh
MVP [MS Access]
Works perfectly!
When I open the main form, I get an Invalid Use of Null error, which
points to this line (in the On Load of the subform):
For k = Me.RecordCount + 1 To 4
This is odd, because every person in this database has at least one
visit right now, and the main form isn't set to go to a new record on
open (I turned that off), so I'm not sure what 'Null' it's detecting.
So I changed it to this:
Dim k As Integer
If IsNull(Me.RecordCount) Then
Exit Sub
Else
For k = Me.RecordCount + 1 To 4
Me("txtVisit" & k).Visible = False
Next k
End If
With this change, I no longer get the Invalid Use of Null error when I
open the main form. Instead, I get a Type Mismatch error, which points
to this line (in the On Current of the main form)
Me.frmReferrals.Form.Form_Load
###
I'll keep chipping away at it. Thanks again for your continued help.