Generate the next number from the table

G

Guest

Hello, Is anyone can help me on this.
I have one table, but I have two forms enter data into this table.
Form1 and Form2 using by different group, but data all save in one table.
How can I write a code to generate the number in both forms.
for example, when Group1 open Form1 to enter new data, Access generate the
new number=Last record number+1.
When Group2 open Form2 to enter new data, Access does the same.
But no duplicate. I set the number as a primary key.

Thank you.
 
G

Guest

My first question is why are there two different forms for the same table?
Why can't they all use the same form?

This is not a difficult thing to do. The place to do it is in the Current
event of the form. Use the NewRecord propertry to do it only for new records:

If Me.NewRecord Then
Me.txtTheNumber = Nz(DMax("[TheNumberField]", "YourTableName"), 0) + 1
End If

txtTheNumber is the control on your form where you display the number.
 
G

Guest

I think you are right, I made it too complicate.
Because I already have two yes/no field in the table for Group1 and Group2.
So in the form I have two check box for Group1 and Group 2.
Actural I can use one form for both group, but the problem is when I print
the report. How can I make sure group 1 and group 2 is showing in the top of
the print out. So the manager knows the print out belongs to each group?

Appreciate for your help.

Klatuu said:
My first question is why are there two different forms for the same table?
Why can't they all use the same form?

This is not a difficult thing to do. The place to do it is in the Current
event of the form. Use the NewRecord propertry to do it only for new records:

If Me.NewRecord Then
Me.txtTheNumber = Nz(DMax("[TheNumberField]", "YourTableName"), 0) + 1
End If

txtTheNumber is the control on your form where you display the number.
Hong said:
Hello, Is anyone can help me on this.
I have one table, but I have two forms enter data into this table.
Form1 and Form2 using by different group, but data all save in one table.
How can I write a code to generate the number in both forms.
for example, when Group1 open Form1 to enter new data, Access generate the
new number=Last record number+1.
When Group2 open Form2 to enter new data, Access does the same.
But no duplicate. I set the number as a primary key.

Thank you.
 
G

Guest

I wouldn't have two check boxes. I would have one Integer field for
[GroupNumber]. Sooner or later, there will be a group 3.
It is one of those old adages. As soon as you Say "There will never be more
than {insert a number here} {Insert Anything here} in our organization",
there is.

If you are only allowing group 1 to use group 1 data and group 2 to only use
group 2 data. You can handle this several ways. You can have a table of
users and which group they belong to. When the app opens, query the user's
login name and look in the table to see which group they belong to. Filter
the row source of their forms and reports based on the group number. As to
putting it on a report, you can have the report check the form for the value.
Put a hidden control on the form that has the group number in it.

Hong said:
I think you are right, I made it too complicate.
Because I already have two yes/no field in the table for Group1 and Group2.
So in the form I have two check box for Group1 and Group 2.
Actural I can use one form for both group, but the problem is when I print
the report. How can I make sure group 1 and group 2 is showing in the top of
the print out. So the manager knows the print out belongs to each group?

Appreciate for your help.

Klatuu said:
My first question is why are there two different forms for the same table?
Why can't they all use the same form?

This is not a difficult thing to do. The place to do it is in the Current
event of the form. Use the NewRecord propertry to do it only for new records:

If Me.NewRecord Then
Me.txtTheNumber = Nz(DMax("[TheNumberField]", "YourTableName"), 0) + 1
End If

txtTheNumber is the control on your form where you display the number.
Hong said:
Hello, Is anyone can help me on this.
I have one table, but I have two forms enter data into this table.
Form1 and Form2 using by different group, but data all save in one table.
How can I write a code to generate the number in both forms.
for example, when Group1 open Form1 to enter new data, Access generate the
new number=Last record number+1.
When Group2 open Form2 to enter new data, Access does the same.
But no duplicate. I set the number as a primary key.

Thank you.
 

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