Duplicate Numbers

R

rml

I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 
R

rml

Then where should I post this?

Klatuu said:
Cross posting is frowned upon.
Please visit this site for info:
http://www.mvps.org/access/netiquette.htm
--
Dave Hargis, Microsoft Access MVP


rml said:
I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 
K

Klatuu

In any one of the groups is fine. Based on the question, perhaps Modulesdaovba

Please understand I don't mean to beat you up. My intent is to help. Many
participants will ignore multi posted questions.
--
Dave Hargis, Microsoft Access MVP


rml said:
Then where should I post this?

Klatuu said:
Cross posting is frowned upon.
Please visit this site for info:
http://www.mvps.org/access/netiquette.htm
--
Dave Hargis, Microsoft Access MVP


rml said:
I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 
R

rml

I posted in the forms coding group because it is an access forms question.
Under the access groups, I don't see anything for Modulesdaovba, so I'm not
sure why this is not the correct group??

Klatuu said:
In any one of the groups is fine. Based on the question, perhaps Modulesdaovba

Please understand I don't mean to beat you up. My intent is to help. Many
participants will ignore multi posted questions.
--
Dave Hargis, Microsoft Access MVP


rml said:
Then where should I post this?

Klatuu said:
Cross posting is frowned upon.
Please visit this site for info:
http://www.mvps.org/access/netiquette.htm
--
Dave Hargis, Microsoft Access MVP


:

I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 
K

Klatuu

Perhaps it just isn't mapped in your newsreader, but it doesn't matter that
much. Many posts are in a group that doesn't seem correct. It is only to
help you get the best answer. The point is, one group, not several.

--
Dave Hargis, Microsoft Access MVP


rml said:
I posted in the forms coding group because it is an access forms question.
Under the access groups, I don't see anything for Modulesdaovba, so I'm not
sure why this is not the correct group??

Klatuu said:
In any one of the groups is fine. Based on the question, perhaps Modulesdaovba

Please understand I don't mean to beat you up. My intent is to help. Many
participants will ignore multi posted questions.
--
Dave Hargis, Microsoft Access MVP


rml said:
Then where should I post this?

:

Cross posting is frowned upon.
Please visit this site for info:
http://www.mvps.org/access/netiquette.htm
--
Dave Hargis, Microsoft Access MVP


:

I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 
O

Ofer Cohen

Hi,

I'm a bit confused about what you are trying to achieve, why you are saving
this value in a seperate table?

Don't run DMax twice, assign the value you got from the first time

Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset

X = DMax("[number]", "[Numbers]") + 1
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select * From Numbers Where number Is Null")
rs.AddNew
rs![number] = X
rs.Update
Me![Spectra] = X

--
Good Luck
BS"D


rml said:
Then where should I post this?

Klatuu said:
Cross posting is frowned upon.
Please visit this site for info:
http://www.mvps.org/access/netiquette.htm
--
Dave Hargis, Microsoft Access MVP


rml said:
I'm using the following code to create number + one. It works fine. On my
form, the user clicks this button and the number is generated. This is a
network situation. Sometimes, we see the number duplicated? Is there any
code I can add to prevent this form happening? Thanks.

Private Sub Command95_Click()
Dim X As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Numbers")
rs.MoveLast
X = DMax("[number]", "[Numbers]") + 1
Me![Spectra] = DMax("[number]", "[Numbers]")
rs.AddNew
rs.Fields(0).Value = X
rs.Update
End Sub
 

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