Really quick Nz(Dmax) question

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 :)
 
J

John W. Vinson

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]
 
C

Carl Rapson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top