• Default Value Previous Field? (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Default Value Previous Field? (Access 2000)

    Author
    Topic
    #362358

    Hi All!

    Working with a data entry form in Access 2000, and I’m trying to do something with a textbox I thought would be simple….

    I’d like to make the default value of the text box to be the previous record of that text box i.e. we may be entering the same supplier for 20 records in a row. Any ideas?

    Tim

    Viewing 0 reply threads
    Author
    Replies
    • #550047

      There are a couple of ways to do it, but the simplest would probably be to use the AfterUpdate event of the textbox to set its defaultvalue property to the textbox’s value. That way when you enter a new value, that will be stored in the defaultvalue property and should come up when you move to a new record. If you need detailed assistance, post back.

      • #550617

        Thanks for your prompt reply–A nice elegant solution solution, which I sadly can’t get to work. It’s a combo box, and I’m putting [comboboxname].DefaultValue=[comboboxname].Text in the AfterUpdate property of the c-box. Even tried .Value. Nothing doing. Am I being a little oversimplistic?

        Tim

        • #550624

          You’re a bit astray – AfterUpdate is an event and it is expecting to see some code (or a macro or something like that). On the Data tab you should see a Default Value property as the third item down. You should be able to set it to the name of the text box.

          I have a broader question however. It sounds as though your table may not be normalized – that is you are storing all of the supplier details in every record. This is where relational databases shine. You have one supplier record, and lots of detail records which have a pointer to the supplier record. Usually that pointer is the primary key for the supplier record. That makes data entry much easier – you can do something like pick the supplier name out of a combo box and then type in the detail data.

          Another trick that may be useful is the data entry short-cut key CTRL/’ – that copies that data from the previous record into the current field. Hope all this helps – Charlotte will probably have some additional insights when the sun reaches her timezone.

          • #550883

            Hi again!

            Maybe I need to be clearer. I have a combo box on a form, where the user (me, the poor typist) enters the supplier name for a received piece of inventory. It

            • #551085

              This is a bound combobox, right? If it isn’t bound then the default property doesn’t do anything. Since you mentioned a textbox originally, I hadn’t realized you were dealing with a combobox. You can do it with code something like this, using the AfterUpdate event of the combo to populate its Tag property and then using that value in the form’s Current event to set the combobox’s value if it’s a new record:

              Private Sub cboCustomerID_AfterUpdate()
                Me.cboCustomerID.Tag = Me.cboCustomerID.ListIndex
              End Sub 'cboCustomerID_AfterUpdate()
               
              Private Sub Form_Current()
                Dim cbo As ComboBox
                
                Set cbo = Me.cboCustomerID
                If Me.NewRecord Then
                  If IsNumeric(cbo.Tag) Then
                    cbo = cbo.ItemData(CLng(cbo.Tag))
                  End If 'IsNumeric(cbo.Tag)
                End If 'Me.NewRecord
                Set cbo = Nothing
              End Sub 'Form_Current()
        • #550634

          Hi Tim,
          Are you getting any errors at all? I can’t see anything wrong with that code (I’m assuming you put it in a Sub procedure rather than just typing it into the AfterUpdate property box, in which case you’ll probably get a macro error message)

    Viewing 0 reply threads
    Reply To: Reply #550047 in Default Value Previous Field? (Access 2000)

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

    Your information:




    Cancel