Results 1 to 11 of 11

Thread: [RESOLVED] Number Generation

  1. #1

    Thread Starter
    Lively Member preethi_rjs's Avatar
    Join Date
    Dec 2006
    Posts
    80

    Resolved [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.

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Re: Number Generation

    Set rs2 = d.Execute("select max(val(no)) from payment")

    Change This

    VB Code:
    1. "select max(no) from payment"

  3. #3
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Number Generation

    Maybe this?
    Text5.Text = Format(Clng(Text5) + 1, "0000#")

  4. #4

    Thread Starter
    Lively Member preethi_rjs's Avatar
    Join Date
    Dec 2006
    Posts
    80

    Red face Re: Number Generation

    No.

    Both replies are not working.

    same 00001 is appearing in Text5.
    Preethi.

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Number Generation

    Have a Look at this thread
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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?

  7. #7

    Thread Starter
    Lively Member preethi_rjs's Avatar
    Join Date
    Dec 2006
    Posts
    80

    Red face 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.

  8. #8
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Number Generation

    you could do

    VB Code:
    1. Format$(Clng(text1.text) + 1, "00000#")

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Number Generation

    Quote 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.

  10. #10
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    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.

  11. #11
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Number Generation

    try this
    VB Code:
    1. Dim Sql As String
    2. Sql = "Select Max(Val([No])) As MaxNo From Payment"
    3. rs2.Open Sql, D, adOpenKeyset, adLockOptimistic
    4. Text5.Text = Format(Val(rs2!MaxNo & "") + 1, "00000")
    5. rs2.Close
    and I found this is of no use
    Quote 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
  •  



Click Here to Expand Forum to Full Width