Results 1 to 4 of 4
  1. #1
    rice1973 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    3

    Data being limited in one field with entry from another

    I have a customer and an address field on a form. Once a customer name is inputted the Address field needs to be limited to the addresses for that customer. I am currently able to do this with the following code:



    Dim Source As String
    Dim CustomerLookup As Long

    CustomerLookup = Me.CustomerLookup.Value
    Source = "SELECT GrowCustAddr.AddrID, GrowCustAddr.Addr, GrowCustAddr.Addr2, GrowCustAddr.Addr3, GrowCustAddr.City, GrowCustAddr.StateProvince, CatState.StateAbbreviation, "
    Source = Source & "GrowCustAddr.Zip , GrowCustAddr.Country, CatCountry.Country, GrowCustAddr.GrowCustID, GrowCustAddr.AddrType, CatAddrType.AddrType "
    Source = Source & "FROM CatState Right Join (CatCountry Inner Join (GrowCustAddr Inner Join CatAddrType ON GrowCustAddr.AddrType = CatAddrType.AddrTypeID) ON CatCountry.CountryID = GrowCustAddr.Country) on CatState.StateID = GrowCustAddr.StateProvince "
    Source = Source & "WHERE GrowCustAddr.GrowCustID = " & CustomerLookup & " "
    Source = Source & "ORDER BY GrowCustAddr.[AddrType]"

    Me.CustomerAddress.RowSource = Source

    However, the problem I have is that once you select a customer for a new or old record then the address field shows blank when you scroll through the records. You can click on the address field and then it shows the correct address that was in it. When I do a compact and repair it fixes this issue until you add or change another record.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    On form in continuous or datasheet view, that is expected behavior with comboboxes using conditional RowSource with alias lookup. Compact & Repair has no impact - close and reopen the form should accomplish the same 'fix'. This is a common topic.

    One approach is to include GrowCustAddr table in the form RecordSource, join type "Include all records from {primary data table} and only those from GrowCustAddr that match". Bind textboxes to GrowCustAddr fields and set them as Locked Yes, TabStop No.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rice1973 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    3
    I am wanting to limit the address drop down to only those addresses that go with that customer. The control source for the form is a query and the growcustaddr table is already a part of it. I tried this and it does not limit the list to the customer on that rowset.



    Quote Originally Posted by rice1973 View Post
    I have a customer and an address field on a form. Once a customer name is inputted the Address field needs to be limited to the addresses for that customer. I am currently able to do this with the following code:

    Dim Source As String
    Dim CustomerLookup As Long

    CustomerLookup = Me.CustomerLookup.Value
    Source = "SELECT GrowCustAddr.AddrID, GrowCustAddr.Addr, GrowCustAddr.Addr2, GrowCustAddr.Addr3, GrowCustAddr.City, GrowCustAddr.StateProvince, CatState.StateAbbreviation, "
    Source = Source & "GrowCustAddr.Zip , GrowCustAddr.Country, CatCountry.Country, GrowCustAddr.GrowCustID, GrowCustAddr.AddrType, CatAddrType.AddrType "
    Source = Source & "FROM CatState Right Join (CatCountry Inner Join (GrowCustAddr Inner Join CatAddrType ON GrowCustAddr.AddrType = CatAddrType.AddrTypeID) ON CatCountry.CountryID = GrowCustAddr.Country) on CatState.StateID = GrowCustAddr.StateProvince "
    Source = Source & "WHERE GrowCustAddr.GrowCustID = " & CustomerLookup & " "
    Source = Source & "ORDER BY GrowCustAddr.[AddrType]"

    Me.CustomerAddress.RowSource = Source

    However, the problem I have is that once you select a customer for a new or old record then the address field shows blank when you scroll through the records. You can click on the address field and then it shows the correct address that was in it. When I do a compact and repair it fixes this issue until you add or change another record.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    My suggestion should not have altered the combobox which you said was already working. So I don't understand the issue.

    Why have StateProvince and StateAbbreviation? I would set the combobox RowSource property:

    SELECT AddrID, Addr, Addr2, Addr3, City, StateProvince, GrowCustAddr.Country, Zip FROM CatState RIGHT JOIN (CatCountry INNER JOIN GrowCustAddr INNER JOIN CatAddrType ON GrowCustAddr.AddrType = CatAddrType.AddrTypeID) ON CatCountry.CountryID = GrowCustAddr.Country) ON CatState.StateID = GrowCustAddr.StateProvince WHERE GrowCustID = [CustomerID] ORDER BY GrowCustAddr.[AddrType];

    Then code behind customer combobox:

    Me.cbxAddress.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Limited date in field
    By mosquito_admin in forum Forms
    Replies: 4
    Last Post: 02-28-2012, 01:20 PM
  2. Limited characters in a memo field
    By Robbyp2001 in forum Forms
    Replies: 11
    Last Post: 11-24-2011, 07:04 AM
  3. Automatic Field DAta Entry
    By Lupson2011 in forum Access
    Replies: 4
    Last Post: 09-01-2011, 09:15 AM
  4. Replies: 4
    Last Post: 01-23-2011, 09:01 PM
  5. MDB database field limited to 64 or 255 characters
    By galapogos in forum Programming
    Replies: 1
    Last Post: 04-06-2010, 10:22 AM

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