Results 1 to 6 of 6
  1. #1
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61

    Selecting a corresponding table field based on text field.

    For some reason cant quite wrap my brain around what should be a relatively simple problem.

    Scenario:
    User enters their login name in a field on a form. The form name is Login and the field is Text1. User clicks on a button, called Command1. Based on Text1, the form looks at the matching Associate field (ie, user enters michael and the record where Associate field is michael is selected) and its corresponding Pref1 field both which are in Table2. The Pref1 field holds a variable that determines which form opens up.

    I presume the above is done with VBA for the Onclick event for Command1. What would the code look like? I realize a combo box would be easier than a text field but Im trying to make the db a little more secure by not displaying everyones login name.




    Thanks in advance.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    when you are doing something like this, the best thing is probably to write a universal function that you can pass variables to. for example, the following function takes a "criteria" variable. the criteria is used to determine which form is opened:
    Code:
    public function whichform( criteria as string)
    
       if criteria = "mark" then
          docmd.openform "form1"
       else
          docmd.openform "form2"
       end if
    
    end function
    make sense?

  3. #3
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    I do understand basicly what youre saying about using a public function to store the value which makes a lot of sense. But the core problem I am having isnt so much the storing of the information but the association of information.

    So what I dont understand how to do is to take the user entered text field, compare it to the user name field in a table and then extract from the table the corresponding Pref1 field.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by michaeljohnh View Post
    take the user entered text field, compare it to the user name field in a table
    Code:
    dlookup("username", "table", "[username] = '" & me.UserTextField & "'")
    Quote Originally Posted by michaeljohnh View Post
    and then extract from the table the corresponding Pref1 field.
    Code:
    dlookup("pref1", "table", "[username] = '" & me.UserTextField & "'")
    so, in essence, use the second code.

    you're looking up based on input. the second piece of code is just fine.

    (hth)

  5. #5
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    Perfect! Thank you very much. Conceptually I knew what I needed to do but could not find the right command and syntax. I gave you the rep boost. Hopefully you level up .

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by michaeljohnh View Post
    you level up .
    only if we're playing dragon warrior on NES. good luck sir.

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

Similar Threads

  1. Replies: 7
    Last Post: 11-24-2014, 02:11 PM
  2. Populating attachment field based on text box
    By justinwright in forum Forms
    Replies: 16
    Last Post: 09-22-2010, 08:38 AM
  3. Replies: 2
    Last Post: 09-20-2010, 09:02 PM
  4. Replies: 2
    Last Post: 05-05-2010, 02:52 PM
  5. Replies: 4
    Last Post: 09-03-2009, 02:01 PM

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