Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Unanswered: How do I use a variable for the default value of a combo box?

    I have a combo box (last_name) and I would like to populate the default value with a variable (techID). The variable will be assigned a value from a button. I have a multi user DB and would like the user to select a button with their name and then when they enter a form it will have their name auto fill the appropriate combo box when they add a new record.

    If I enter the string "Smith" as the default value in the properties of the combo it works how I would like it to. But I have multiple users and have a need to make it a variable. Any ideas?

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You could pass the variable as an openarg

    Docmd.OpenForm "YourForm,,,,,,TechId
    and in the form's OnOpen event
    Me![last_name]=Me.Openargs

    or Declare it as a global variable
    and in the form's OnOpen event
    Me![last_name]=TechId
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2007
    Posts
    3
    I received this code from another source but I thought I would post it here for others to benefit. This works great it autofills a default and uses this value to select from a table. I hope someone else can use this

    ---------------------------------------------
    Create a function in a module:
    Code:

    Public techID as String 'you should already have this part
    Function GettechID()
    GettechID = techID
    End Function


    Then, in the Default Value for your combo put:
    Code:

    =Nz(GettechID(),"No TechID!")
    ---------------------------------------------

    Credit goes to CraigDolphin
    Thanks Craig

  4. #4
    Join Date
    Sep 2006
    Posts
    265
    If you have a start Menu put the TechID on this menu and reference it, the default value can be set to =[Forms]![Menu]![TechID] or you can write some code to establish the TechID from the environ$("UserName")

  5. #5
    Join Date
    Jan 2007
    Posts
    3
    Thanks for the reply Simon. I see what you are getting at but my startup form is a switchboard.

    What I did is put a form in sequence between my switchboard and my main form. This form has a button for each of my different users. From there I used the code I posted above in my default value. It works nice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •