Results 1 to 5 of 5
  1. #1
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10

    Auto fill Drop down box for current records

    Hi all



    So ill try and get this down in a way that does not just make sense to me!

    Ok i have a database

    two tables: Addresses, Instructions
    One form_one subform: User form

    The user form contains set of instructions for each company that we take care off, the sub-form has all of the addresses for the company, these come from the "Address" table, the two are linked via a field called "companyID" so the subform only displays the addresses for the current company being viewed on the form.

    The problem is, on the subform there is a dropdown box called "administrator" and this is used to select the person who is looking after the company. Some of the companies have hundreds of addresses, so when i click the next record button on the subform I have to fill in the administrator again for every address for the same company. Is there a way using vba or a simple function to auto update all of the "administrator" dropdown boxes for that company based on the administrator I select for the first address.

    Cheers guys n gals

    ps access 2010
    Last edited by neoroses; 01-23-2014 at 06:08 AM. Reason: missed summit

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You can use the AfterUpdate event of the Control holding your data to set the DefaultValue for the Field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each New Record.

    Code:
    Private Sub YourControlName_AfterUpdate()
       Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
    End Sub

    Just replace YourControlName with the actual name of your control for the administrator's name.

    This syntax is valid for Text, Number, DateTime and Boolean Datatypes.

    Linq ;0)>

  3. #3
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    Thank dude, this did not work, is this because the values in my dropdown box were typed? should i have the values stored in another table?

    Thanks again man i really appreciate the help

  4. #4
    neoroses is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    10
    this is what i put:

    my drop downbox is call administrator



    Private Sub Administrator_AfterUpdate()
    Me.Administrator.DefaultValue = """" & Me.Administrator.Value & """"
    End Sub

    is that correct?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Looks right....

    I just tested Linq's code and it worked for me. (although I don't type the ".Value" since it is the default property - personal preference)
    You have to type in the administrator name once (or whenever the name changes).

    The control "Administrator" is bound to a text field in the record source?

    You added the code to the sub-form module? Not the main form module? (Just asking since I cannot see your dB)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto fill
    By jojomac in forum Access
    Replies: 1
    Last Post: 10-10-2012, 09:57 AM
  2. Auto Fill
    By Scotty J in forum Forms
    Replies: 10
    Last Post: 11-21-2011, 10:08 AM
  3. Replies: 1
    Last Post: 11-13-2011, 08:01 AM
  4. Auto fill Current year
    By Bhat59 in forum Forms
    Replies: 3
    Last Post: 10-17-2011, 08:56 PM
  5. can't auto fill
    By chrisrach3 in forum Access
    Replies: 7
    Last Post: 09-12-2011, 04:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums