Really quick Nz(Dmax) question

  • Thread starter Thread starter NoviceNana
  • Start date Start date
N

NoviceNana

Trying to create a counter field on my subform:
The field on the subform that will hold the count is called
"CounterNew"
the mainform is called frm_weekly
the subform is called tbl_encounter_subform

This is my code:
Private Sub Form_Current()

If Me.NewRecord Then
Me.CounterNew = 1 + Nz(DMax("CounterNew", "tblEncounters", "IDNumber="
& Me.IDNumber), 0)
End If
End Sub

Nothing is happening.
Can anyone tell me why?
Nana :-)
 
Trying to create a counter field on my subform:
The field on the subform that will hold the count is called
"CounterNew"
the mainform is called frm_weekly
the subform is called tbl_encounter_subform

This is my code:
Private Sub Form_Current()

If Me.NewRecord Then
Me.CounterNew = 1 + Nz(DMax("CounterNew", "tblEncounters", "IDNumber="
& Me.IDNumber), 0)
End If
End Sub

Nothing is happening.
Can anyone tell me why?
Nana :-)

Well... asking the question four times wasn't really necessary...

I'd use the Form's BeforeInsert event instead. I *assume* that IDNumber is the
primary key of the main form's recordsource, and that the foreign key to
IDNumber is in the subform's Recordsource.

John W. Vinson [MVP]
 
NoviceNana said:
Trying to create a counter field on my subform:
The field on the subform that will hold the count is called
"CounterNew"
the mainform is called frm_weekly
the subform is called tbl_encounter_subform

This is my code:
Private Sub Form_Current()

If Me.NewRecord Then
Me.CounterNew = 1 + Nz(DMax("CounterNew", "tblEncounters", "IDNumber="
& Me.IDNumber), 0)
End If
End Sub

Nothing is happening.
Can anyone tell me why?
Nana :-)

It depends on what you mean by "nothing is happening". Does the CounterNew
control remain empty when you move to a new record in the subform? If so, it
seems to me that there might be a problem with the DMax call, because even
if DMax were returning a Null value you should see a value of 1 in the
CounterNew box. Double check your field and table names. Is there actually a
field named CounterNew in tblEncounters? Is the CounterNew control on the
subform bound to that field?

You could also place a breakpoint on the line containing the DMax call and
see if that line is ever reached whehn your form executes. In debug mode,
you might be able to spot something.

Carl Rapson
 
Back
Top