Did you check the references and of course it should always be a first did you try to reboot? It is strange.
Problems with DCount
Collapse
X
-
Yes everything checks out. I opened the db you sent right from the email and I still get the error. :*-(Comment
-
Hi Melissa,
RecordCount can sometimes be a problem. Try the following ...
[code=vb]
Private Sub Form_Current()
Dim rs As Object
If Me.Parent.NewRe cord = True Then Exit Sub
If Me.Dirty Then
DoCmd.RunComman d acCmdSelectReco rd
DoCmd.RunComman d acCmdSaveRecord
End If
Set rs = Me.RecordsetClo ne
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > Me.Parent.Speci menCount Then
Me.Parent.Speci menCount = rs.RecordCount
End If
rs.Close
Set rs = Nothing
End Sub
[/code]
MaryComment
-
-
MelissaOriginally posted by mmccarthyHi Melissa,
RecordCount can sometimes be a problem. Try the following ...
[code=vb]
Private Sub Form_Current()
Dim rs As Object
If Me.Parent.NewRe cord = True Then Exit Sub
If Me.Dirty Then
DoCmd.RunComman d acCmdSelectReco rd
DoCmd.RunComman d acCmdSaveRecord
End If
Set rs = Me.RecordsetClo ne
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > Me.Parent.Speci menCount Then
Me.Parent.Speci menCount = rs.RecordCount
End If
rs.Close
Set rs = Nothing
End Sub
[/code]
Mary
Did you put this in the current event of the subform?
MaryComment
-
-
Try this so we can see where the problem is.
[code=vb]
Private Sub Form_Current()
Dim rs As Object
Set rs = Me.RecordsetClo ne
rs.MoveLast
rs.MoveFirst
Msgbox "Subform Record Count is " & rs.RecordCount & _
" and SpecimanCount is " & Me.Parent.Speci menCount
rs.Close
Set rs = Nothing
End Sub
[/code]
MaryComment
-
Okay let's see. When I open frm_Entrainment and hit the "View or Add Specimens" button, which opens the form that contains the subform with the code in question, then I get "No current record" and when I debug it highlights "rs.MoveLas t".Comment
-
OK, now try putting this in the current event of the main form and see what happens (don't forget to substiture your subformName)
[code=vb]
Private Sub Form_Current()
Dim rs As Object
Set rs = Me.SubformName. Form.RecordsetC lone
rs.MoveLast
rs.MoveFirst
Msgbox "Subform Record Count is " & rs.RecordCount & _
" and SpecimanCount is " & Me.SpecimenCoun t
rs.Close
Set rs = Nothing
End Sub
[/code]
MaryComment
-
Do you mean the form that contains the subform?
Basically the user opens frm_Entrainment and clicks the button to take them to frm_Specimen_En trainment. On this form is the subform "sbfrm_FishSpec imen_Entrainmen t". It is this subform that I have the above Form_Current code on.Comment
-
Yes I mean the form that has the subformOriginally posted by AccessIdiotDo you mean the form that contains the subform?
Basically the user opens frm_Entrainment and clicks the button to take them to frm_Specimen_En trainment. On this form is the subform "sbfrm_FishSpec imen_Entrainmen t". It is this subform that I have the above Form_Current code on.Comment
-
I am so sorry for such a slow reply been busy...
Generally speaking for most recordsets that provide a recordcount you can generally request a recordcount as such. If it is zero then there are no records and a move first or last will cause an error as will most recordset calls.Originally posted by AccessIdiotOkay let's see. When I open frm_Entrainment and hit the "View or Add Specimens" button, which opens the form that contains the subform with the code in question, then I get "No current record" and when I debug it highlights "rs.MoveLas t".
[CODE=vb]if rs.RecordCount > 0 then
do this
end if[/CODE]
Or another more popular method since it will be recognized by most recordsets
[CODE=vb]If Not rs.EOF And Not rs.BOF Then
do this
end if[/CODE]
Otherwise you will receive the error "No current record"Comment
-
Another reason the EOF or BOF method is used is that there are times when a recordset needs to be populated before you can retrieve a recordset which is why Mary sugested the Movefirst moveLast methods, which is also a good practice for coding to prevent issues that may arise as such.Comment
-
Right. Now it's hanging on rs.MoveLast with the error message "No current record". The lines of comprehension have started to blur and I am at a loss what to do here?
Denburt should I use something like thisaround the rs.MoveLast rs.MoveFirst?Code:If Not rs.EOF And Not rs.BOF Then
Comment
-
Code:Private Sub Form_Current() Dim rs As DAO.recordset Set rs = Me.SubformName.Form.RecordsetClone [B]If Not rs.EOF And Not rs.BOF Then[/B] rs.MoveLast rs.MoveFirst Msgbox "Subform Record Count is " & rs.RecordCount & _ " and SpecimanCount is " & Me.SpecimenCount [B]End if[/B] rs.Close Set rs = Nothing End SubComment
Comment