• Problem with Max Value (Acc 97 sr2 on 95b)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Problem with Max Value (Acc 97 sr2 on 95b)

    Author
    Topic
    #363946

    I have a NewCustomer form tied directly to the table Customer. This form is set to open in Data entry mode. The AccNo field is a text field that has either a 650000 number for account customers or a C00000 number for cash sale customers.

    I have a list box squashed to show only one value that shows the last C number entered using the row source as:
    SELECT Customer.AccNo FROM Customer WHERE (((Customer.AccNo) Like “C0????”)) ORDER BY Customer.AccNo DESC;

    The salesmen are allowed to put up new customers as cash sale accounts only, and at the moment they manually type in the next C number from the one shown.

    I have attempted to automate this step by doing the following:
    Dim begin, finish, cnt
    begin = “C00000”
    finish = Right(Listbox.Value, 5)
    finish = finish + 1
    cnt = Len(finish)
    AccNo.Value = Left(begin, 6 – cnt) & finish

    on formload but I have found that the listbox has no value until a value in the box is clicked, so I get a null error and the process is not automatic.

    How can I achieve having the form open into Dataentry mode with the next C number in position?

    Regards, Allan

    Viewing 0 reply threads
    Author
    Replies
    • #557093

      There are a number of approachs to solving your problem. I would consider making the Cash ‘number’ an integer rather than text and increment it using code. To distinguish it from an Account sale you can concatenate the ‘C’ to the number to display it on your form. Code like this in the On Current event of the form will lookup the last number assigned and increment it by one:

      If Me.NewRecord Then
      On Error Resume Next
      Me!CashSale.DefaultValue = Nz(DMax(“[CashSaleID]”, “tblCustomer”), 0) + 1
      End If

      I would make the ID field invisible and put an unbound field on the form with the Control Source set to:

      =”C” & Format([CashSaleID],”00000″).

      This will give you the ‘look’ that you want while still storing an integer in the ID field.

      hth,
      Jack

      • #557095

        Unfortunately, the table is well under way and the codes are mixed in together

        eg
        650012
        651059
        C00359
        650126
        etc

        The 65???? codes are not set by me.
        As cash sale customers move to Accounts, their C code is changed to a 65 code with no relation between them.

        How do I write a Dlookup or SQL code to return me the highest value of the C codes. If I can do this all in code, I can increment it as above and then assign it to the text control. (Can I???)

        Regards, Allan

        • #557096

          This code will find the highest number that starts with a ‘C’ and add one to it:

          Me.CashID = Format(Mid(DMax(“AccNo”,”YourTable”,”(Left([AccNo],1) = ‘C’)”),2)+1,”00000″)

          The code above is courtesy of Mr. Ricky Hicks with whom I have been discussing this with. I was of a mind to add another field for Acct. Type and place a C or a 65 there and just let the other field be an integer and increment it and then concatenate the Acct. Type for viewing purposes.

          Good luck!

          Jack

          • #557100

            If you want the “C” as the prefix then make a slight change to the code:

            Me.CashID = “C” & Format(Mid(DMax(“AccNo”,”YourTable”,”(Left([AccNo],1) = ‘C’)”),2)+1,”00000″)

            HTH
            RDH

          • #557102

            Many Thanks Jack and to Ricky as well,
            That bit of code was just what I needed.

            How would I cope without places like this!!!

            Regards, Allan

            • #557103

              “Our” pleasure. Continued success with Access…

              Jack

            • #557108

              You are very welcome ….. smile

              I glad it made Jack scratch his “old” head ….. LOL

              RDH

    Viewing 0 reply threads
    Reply To: Problem with Max Value (Acc 97 sr2 on 95b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: