Results 1 to 10 of 10
  1. #1
    ageurtse is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    May 2017
    Location
    Netherlands
    Posts
    10

    filling text field from dbgrid

    Hello,

    i'm trying to build a form with several text fields.
    these text fields should populated by a record selected from a dbgrid.
    is this possible and how can this be done.



    the dbgrid could be used for several different text fields

    i hope you guys get it, don't now how to explain it better.

  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,963
    What do you mean by 'dbgrid'? What exactly is this? Are you coding in VB6 as UI? https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx

    According to that link, values can be 'grabbed' from the control.
    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
    ageurtse is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    May 2017
    Location
    Netherlands
    Posts
    10
    sorry i mean a grid, in the early days i used delphi and there it was called a dbgrid.


    below are some textfields and a grid.
    let's take this as an example.


    in my database i have an owner, user and inspection company.
    all these three text fields should be filled from the grid, which reprecent's all company names, adresses etc. etc.

    all type of adresses are put into one tabel, because a owner could also be a user and maybe is also the company name.
    In most cases those are different.

    now i want to select the right adres from the grid and point it to the right textfield. how can i do this.



  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,963
    That 'grid' is just a subform in Datasheet view.

    You want to select city in the subform and show its detail data on the main form? Might consider the intrinsic Split form.

    However, if the main form is bound to table of Countries and subform is bound to another table of Cities, what you want is not conventional. Normally subform only displays records related to main form record. In such an arrangement subform (child) does not dictate to main form (parent). Conventional approach is combobox on main form to select desired country and use that value to search or filter the main form. So could have UNBOUND multi-column combobox that lists ALL cities and a column could have the associated country.
    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.

  5. #5
    ageurtse is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    May 2017
    Location
    Netherlands
    Posts
    10
    i figured that out my self, but how do i if a record in the subform is selected be placed in on off the selected text boxes.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    I got this to work in the subform's OnClick event:

    Private Sub Form_Click()
    DoCmd.SearchForRecord acDataForm, "Countries", acFirst, "Country='" & Me!Country & "'"
    End Sub

    The textboxes are bound to fields of Countries table.
    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.

  7. #7
    ageurtse is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    May 2017
    Location
    Netherlands
    Posts
    10
    oke this is bound to one textfield, what if i select a different textfield to bound to, how do i program that.

    so i somehow need to select 2 things, the textbox to fill and the record from the subform to use in the selected textbox

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Don't understand. There is no need to select 'textbox to fill'. Just need to move focus on main form to the desired country record. ALL of the textboxes will display data from the fields they are bound to.
    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.

  9. #9
    ageurtse is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    May 2017
    Location
    Netherlands
    Posts
    10
    no you mis understooth my question.

    i'm trying to explain it better.

    Table1:
    ID
    CustomerID
    OwnerID
    InspectionID

    Table2: (Adres)
    ID
    Sirname
    Adres
    zipcode


    Table2 is on the subform

    on the mainform i have 3 text fields: customer, owner and inspection. each of them could have a different id-field from table2

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Why did you show countries and cities image as example, why not your real situation? Whichever, concept still applies.

    You want to show the address associated with CustomerID, OwnerID, InspectionID? Build a query that includes Table2 3 times, 1 each link to each of the 3 fields in Table1. Use that as the RecordSource for main form.

    DoCmd.SearchForRecord acDataForm, "main form name", acFirst, "CustomerID = " & Me!ID & " OR OwnerID = " & Me!ID & " OR InspectionID = " & Me!ID

    That should find the first record that has Table2 ID in any of the 3 fields.

    If you want to allow user to specify which field to search then need UNBOUND combobox on the main form with those 3 choices and reference the combobox:

    DoCmd.SearchForRecord acDataForm, "main form name", acFirst, Me.Parent.cbxField & " = " & Me!ID

    I just really don't understand the usefulness of this arrangement. So you find the first occurrence of the ID on the main form, what will be done with that record?

    Instead of search for first occurrence could apply a filter to the main form. Usefulness of that also escapes me.
    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. Replies: 3
    Last Post: 02-01-2016, 03:14 PM
  2. Replies: 4
    Last Post: 01-10-2016, 01:03 PM
  3. Replies: 2
    Last Post: 11-16-2015, 08:10 AM
  4. Replies: 5
    Last Post: 04-24-2014, 10:02 AM
  5. Filling a combobox with field names.
    By millerdav99 in forum Access
    Replies: 1
    Last Post: 04-26-2011, 02:09 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