DMax

  • Thread starter ladybug via AccessMonster.com
  • Start date
L

ladybug via AccessMonster.com

I need some assistance with the DMax function. I have a form with a subform.
The record source for the subform is SELECT [tbl_detail].[record_id],
[tbl_detail].[parent_no], [tbl_detail].[stc_no], [tbl_detail].[pz_acct_no],
[tbl_detail].[ctr_nm] FROM tbl_detail;

Now on the subform I have a command button named btn_gen_stc. I want to
click this button and in stc_no I want the next highest # from tbl_detail to
appear in the text box.

I started by putting this in the On Click Event of btn_gen_stc:

Private Sub btn_gen_stc_Click()
If Me.NewRecord Then
Me.stc_no = DMax("stc_no", "tbl_detail") + 1
End If
End Sub

Now this is where I am missing something. There is no # generating in stc_no
on the subform. Can someone help me?
 
R

Rick Brandt

ladybug said:
I need some assistance with the DMax function. I have a form with a
subform. The record source for the subform is SELECT
[tbl_detail].[record_id], [tbl_detail].[parent_no],
[tbl_detail].[stc_no], [tbl_detail].[pz_acct_no],
[tbl_detail].[ctr_nm] FROM tbl_detail;

Now on the subform I have a command button named btn_gen_stc. I want
to click this button and in stc_no I want the next highest # from
tbl_detail to appear in the text box.

I started by putting this in the On Click Event of btn_gen_stc:

Private Sub btn_gen_stc_Click()
If Me.NewRecord Then
Me.stc_no = DMax("stc_no", "tbl_detail") + 1
End If
End Sub

Now this is where I am missing something. There is no # generating
in stc_no on the subform. Can someone help me?

Does tbl_detail already contain at least one record? Your DMax() will only
work if there is at least one existing record. If not, then you need to add
the Nz() function like...

Me.stc_no = Nz(DMax("stc_no", "tbl_detail"), 0) + 1

Are you definitely on a new record?
 
L

ladybug via AccessMonster.com

Yes, tbl_detail has hundreds of records already. Is there any code that I
need to put in the text box stc_no?

Rick said:
I need some assistance with the DMax function. I have a form with a
subform. The record source for the subform is SELECT
[quoted text clipped - 16 lines]
Now this is where I am missing something. There is no # generating
in stc_no on the subform. Can someone help me?

Does tbl_detail already contain at least one record? Your DMax() will only
work if there is at least one existing record. If not, then you need to add
the Nz() function like...

Me.stc_no = Nz(DMax("stc_no", "tbl_detail"), 0) + 1

Are you definitely on a new record?
 
D

Dale Fye

do the [stc_no] fields display properly for the other records that are not
new records? What is the name of the control that is supposed to display
this value?

Have you stepped through the code to make sure the code is actually stepping
into your If Then statement?

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



ladybug via AccessMonster.com said:
Yes, tbl_detail has hundreds of records already. Is there any code that I
need to put in the text box stc_no?

Rick said:
I need some assistance with the DMax function. I have a form with a
subform. The record source for the subform is SELECT
[quoted text clipped - 16 lines]
Now this is where I am missing something. There is no # generating
in stc_no on the subform. Can someone help me?

Does tbl_detail already contain at least one record? Your DMax() will only
work if there is at least one existing record. If not, then you need to add
the Nz() function like...

Me.stc_no = Nz(DMax("stc_no", "tbl_detail"), 0) + 1

Are you definitely on a new record?
 
L

ladybug via AccessMonster.com

This form is only being used to add new records. The text box is called
stc_no and the control source for it is stc_no. I do not have anything else
set on the this text box.

Sorry, how do I step through the code?

Dale said:
do the [stc_no] fields display properly for the other records that are not
new records? What is the name of the control that is supposed to display
this value?

Have you stepped through the code to make sure the code is actually stepping
into your If Then statement?
Yes, tbl_detail has hundreds of records already. Is there any code that I
need to put in the text box stc_no?
[quoted text clipped - 12 lines]
 

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

Top