Ask Experts Questions for FREE Help !
Ask
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #1

    Apr 8, 2015, 10:42 AM
    Microsoft access- Sequential Numbering
    So I am trying to put together a form in Microsoft Access that will autopopulate a demobilization number immediately before saving the record. I am no expert in Access and am not sure where to physically put my coding.
    Here is the coding I am using... the fields are tailored to what I have in my working copy.

    Me.demobgenerator = Nz(DMax("[Demob Number]", "Master Database"), 0) + 1
    DoCmd.RunCommand acCmdSaveRecord

    So where should I put this coding / is it correct for what I want? See below for more details...

    The form based on my query will pick up records that have the status set to demobbing and transfers the selected fields from the datasheet to the appropriate boxes on the form. I would like the demobilization number txt box to automatically recognize the incident number (field in the datasheet) and the apply the next available number (starting at 1 to say 00000) for that demobilization at that incident. (I would also like to have '-D-' separating the info.)
    (Example : Incident-D-001, or TIM001-D-001 but then for another incidient TIM002-D-001, TIM002-D-002, TIM002-D-003... etc.)
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    Apr 8, 2015, 11:16 AM
    Please see my blog on Sequential Numbering. https://scottgem.wordpress.com/2009/...ial-numbering/ It discusses all these issues and more.

    If you have any questions after reviewing the blog please fee free to ask.
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #3

    Apr 8, 2015, 11:35 AM
    Hi Scott,
    I did indeed start my search with reading your blog however, I need clarification as to where the coding would physically go in the VBA? See attached photo... You'll notice I have the coding between savebutton_Click and Private Subsavebutton_Click_Err...

    Attachment 47292
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #4

    Apr 8, 2015, 11:44 AM
    Forgot to mention that I also have the identifier expression already in place on the txtbox that should display the demobilization number.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #5

    Apr 8, 2015, 11:45 AM
    The problem here is that when you generate the number is up to you. The key issues is that you need to commit the record immediately after generating the number to prevent duplication. So you don't want to generate the number until data entry is just about complete.

    I notice that you have a demobgenerator code stub. So it looks like you were going to put it behind a button. Now you have it when you click a text box. Not sure why. Again, you can run the code anytime that makes sense to you. I like to use a button to generate the code and prompt the user that this will save the record as currently entered so they can cancel if it is too soon.

    Does that help?
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #6

    Apr 8, 2015, 12:17 PM
    Ok I see what you are saying... the code was sitting under a txt box... I have now moved it under the savebutton_Click().

    However when I tried to test out the save button, it says I need to debug my code.Attachment 47293
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #7

    Apr 8, 2015, 12:32 PM
    What was the exact error message? Do you have a control on your form named savebutton? Do you have a field in your table named Demob Number?
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #8

    Apr 8, 2015, 12:42 PM
    The error message is :
    Run-time error '-2147352567 (80020009)':
    You can't assign a value to this object.

    savebutton is the name of the command button to save the record. And yes I have a field in my master table named Demob Number.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #9

    Apr 8, 2015, 01:42 PM
    And you do have a textbox control named demobgenerator? The error message is indicating it may not be a control with a value property.
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #10

    Apr 9, 2015, 05:35 AM
    That's correct. The textbox in which I would like the number to generate in is called demobgenerator
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #11

    Apr 9, 2015, 05:38 AM
    It should work then. Can you attach a stripped down version of your app (zip it first). And I'll take a look.
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #12

    Apr 9, 2015, 06:05 AM
    Resource_Tracking_TableEntry TEST - Copy.zip
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #13

    Apr 9, 2015, 11:03 AM
    Ahh I found the problem. The control you were trying to write to has an expression as it's ControlSource. That's why you can't write to it. What you need to do is have a hidden control on the form bound to the Demob Number field and then reference that control in your expression.

    I'm attaching your db back with those changes.
    Attached Files
  1. File Type: zip Resource_Tracking_TableEntry TEST - Copy.zip (246.7 KB, 44 views)
  2. Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #14

    Apr 9, 2015, 12:26 PM
    Hi again,

    Not sure I understood what you said. For some reason the Zip file won't let me open it with the changes you made.
    I don't think I did it correctly because now I am receiving a different message when I hit the saverecord button: #Type!

    So what I did was make a hidden txtbox on the form that was bound to the demob number field in the datasheet. Then I changed the control source on the demob generator txtbox to reflect the first change. So ="-D-" & Format([txtdemob number],"00000") which is in the location of where my number would generate/appear on the form.
    Did I miss something?
    Thanks for your patience on this by the way, I really appreciate your help!
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #15

    Apr 9, 2015, 02:28 PM
    That is basically what I did. Does it work?
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #16

    Apr 10, 2015, 05:40 AM
    No... The txtbox just says #Type! And nothing happens now when I click the saverecord button.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #17

    Apr 10, 2015, 11:00 AM
    You need to change the code behind the SaveRecord button to populate the hidden control you added.
    Ladyk18's Avatar
    Ladyk18 Posts: 10, Reputation: 1
    New Member
     
    #18

    Apr 10, 2015, 12:01 PM
    So I changed the code behind the SaveRecord button to populate the new hidden control I added but I am still getting a the #Type! Error
    as well as Run-time error'-2147352567 (80020009)': You can't assign a value to this object when I hit the saverecord button.

    Image attached is the change I made to the code to populate hidden control in VBA formatAttachment 47306
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #19

    Apr 10, 2015, 12:35 PM
    You can't assign a value to the control demodgenerator because you have an expression as the controlsource. You have to set up a new control with a controlsource of the Demod Number field in the table. You then need to change the SaveRecord code to assign the next number to that new control.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #20

    Apr 11, 2015, 09:05 AM
    Not sure why you had a problem with the zip file so I uploaded the file to my SkyDirve. You can download using this link:

    http://1drv.ms/1JzNn4j

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Sequential numbering in Excel [ 3 Answers ]

Hi, I'm trying to number a column in sequential order by counting the number of times a certain word is typed in another range. For example: AAA 1 BBB 1 AAA 2 AAA 3 CCC 1 I need the numbers to be in sequence in column B:B every time a word is typed multiple times in column A:A.

Excel sequential numbering questions [ 5 Answers ]

I have a spreadsheet with our clients on them, with about 5 columns across the top (name, address, phone #'s, email, comments) and in Column A, I have them numbered. The issue is that they are not all the same number of lines apart. For instance if a client has 3-4 different emails or contact...

Sequential numbering in excel 2007? [ 3 Answers ]

Sequential Numbering in Excel Sheets. Sheet 1 - Copy to Sheet 2 But No in Cell "A1" must Change to next No i.e 0001 to 0002.

Auto Sequential Numbering [ 3 Answers ]

Is there a way within Excel to Auto Generate a new number every time I open a spreadsheet.ie: I made a Purcahse Order template and I would like for Excel to generate a new Purchase Order number whenever I open it up. Can anyone let me know if this is a possibility.


View more questions Search