|
-
Jan 3rd, 2007, 02:38 AM
#1
Thread Starter
Lively Member
[RESOLVED] Number Generation
hi,
i need to generate numbers automatically.
it needs to be of format 00001,00002 and so on...
i tried the following coding. but its not generating consecutive numbers. instead each time 00001 appears on text5.
c = MsgBox("Wish to add a new Payment", vbExclamation + vbYesNo, "Payment Entry")
If c = vbYes Then
Set rs1 = d.Execute("select no from payment")
Do While Not rs1.EOF
rs1.MoveNext
Loop
Set rs2 = d.Execute("select max(val(no)) from payment")
If IsNull(rs2(0)) = True Then
Text5 = "00001"
Else
Text5.Text = Format(rs2(0) + 1, "0000#")
End If
End If
NOTE: no is second column in the database.
Please help me solve this simple problem.
Thank You.
 Preethi. 
-
Jan 3rd, 2007, 02:50 AM
#2
Re: Number Generation
Set rs2 = d.Execute("select max(val(no)) from payment")
Change This
VB Code:
"select max(no) from payment"
-
Jan 3rd, 2007, 02:51 AM
#3
Re: Number Generation
Maybe this?
Text5.Text = Format(Clng(Text5) + 1, "0000#")
-
Jan 3rd, 2007, 03:21 AM
#4
Thread Starter
Lively Member
Re: Number Generation
No.
Both replies are not working.
same 00001 is appearing in Text5.
 Preethi. 
-
Jan 3rd, 2007, 03:23 AM
#5
Re: Number Generation
Have a Look at this thread
Please mark you thread resolved using the Thread Tools as shown
-
Jan 3rd, 2007, 03:28 AM
#6
Re: Number Generation
I don't have anything now for replying, but could you please add [vbcode][/Highlight] tags around your code in the first post and use them from now on?
-
Jan 3rd, 2007, 10:27 AM
#7
Thread Starter
Lively Member
Re: Number Generation
hi,
as the number must preceed with zero's i hav given its datatype as Text and not as number.
so it needs to be converted in number format for incrementing by 1.
 Preethi. 
-
Jan 3rd, 2007, 10:32 AM
#8
Frenzied Member
Re: Number Generation
you could do
VB Code:
Format$(Clng(text1.text) + 1, "00000#")
-
Jan 3rd, 2007, 10:49 AM
#9
Re: Number Generation
 Originally Posted by preethi_rjs
hi,
as the number must preceed with zero's i hav given its datatype as Text and not as number.
so it needs to be converted in number format for incrementing by 1.
Don't do that, make a distinction on how data is stored and how its presented to the user. 00001 is just 1 after all, the leading zeroes are just for aesthetics, just format accordingly when data is being displayed. You can now use the Autonumber feature of your database, if its available. If not, no prob since the Max() function will work with numerics.
Last edited by leinad31; Jan 3rd, 2007 at 11:48 AM.
-
Jan 4th, 2007, 07:05 AM
#10
Re: Number Generation
Have you tried stepping through your code to make sure that IsNull(rs2(0)) is not always true? To set a breakpoint on the line of code you wish to pause at, click on the grey bar on the left next to the line and it should add a dot. When you run the program it will continue to that point and pause, then press F8 to move through the code. To continue normally again press F5. To remove a breakpoint click on the dot.
-
Jan 4th, 2007, 07:13 AM
#11
Re: Number Generation
try this
VB Code:
Dim Sql As String
Sql = "Select Max(Val([No])) As MaxNo From Payment"
rs2.Open Sql, D, adOpenKeyset, adLockOptimistic
Text5.Text = Format(Val(rs2!MaxNo & "") + 1, "00000")
rs2.Close
and I found this is of no use
 Originally Posted by Preethi_rjs
Set rs1 = d.Execute("select no from payment")
Do While Not rs1.EOF
rs1.MoveNext
Loop
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|