Results 1 to 8 of 8
  1. #1
    Traceyann1964 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jan 2015
    Posts
    23

    Autofill a field based on the selection of 2 other fields

    Hello. Hoping someone can help me out.


    I have:- field 1 in my form called "size" where the user can select from a choice of 5
    field 2 called "type" again, the user can select from a choice

    What I want is to autofill a field 3 based on the selection of both fields 1 and 2

    For example, selected from field 1 = "24cm"
    selected from field 2 = "Fitted"

    Field 3 would be autofilled with a code " 12345"

    Hope that makes sense -there could be many combinations

    Fields are from 1 table and those fields are a "look up" from other tables

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Build a query that joins these tables to produce the results needed.
    the query looks at the controls on the form.
    ..select * from tabe1,table2 where table1.field = table2.field

    then you can call DLOOKUP to pull the result based on the 2 picks.....

    vResult= Dlookup("[result]","qsQuery")

  3. #3
    Traceyann1964 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jan 2015
    Posts
    23
    Thanks but they are from the same table. Does that matter?

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Where is the autofill values located? Do you have a table that has the 3 values: 24cm, fitted, 12345 to be able to search on?

  5. #5
    Traceyann1964 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jan 2015
    Posts
    23
    Yes I have 3 other tables for the looks up. TblSizes ,TblTypes and TblOrdercodes

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    I assume TblOrdercodes has Size and Type fields in it also to be able to look up which Ordercode to pull?

  7. #7
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    I think you would use a DLookup as ranman suggested. Check that both combo boxes have values, then lookup the value in TblOrdercodes table(again assume it has Size and Type fields).

    If IsNull(Me.Size) then
    MsgBox "Size must be entered"
    Me.Size.SetFocus
    End
    Else

    If IsNull(Me.Type) then
    MsgBox "Type must be entered"
    Me.Type.SetFocus
    End
    End IF
    End IF

    Me.OrderCode = DLookup("OrderCode" , "TBLOrderCodes" , "Size = '" & Me.Size & "' And "Type = '" & Me.Type & "'")

    On the conditions, if my syntax is right, the quotes are like this:
    SingleQuote DoubleQuote & Me.Size & DoubleQuote SingleQuote
    SingleQuote DoubleQuote & Me.Type & DoubleQuote SingleQuote DoubleQuote

  8. #8
    Traceyann1964 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jan 2015
    Posts
    23
    Thanks - I will see if I can do that

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

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2014, 01:20 PM
  2. Replies: 9
    Last Post: 05-23-2014, 04:18 PM
  3. AutoFill Based on ComboBox Selection
    By chelseagardens in forum Forms
    Replies: 3
    Last Post: 08-08-2013, 01:14 PM
  4. Replies: 3
    Last Post: 06-10-2013, 02:44 PM
  5. Autofill form fields based on another field
    By ljs1277 in forum Access
    Replies: 3
    Last Post: 02-16-2010, 02:51 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