Results 1 to 4 of 4
  1. #1
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76

    How to use listbox to give foreignkey field a value based on selected record

    Hi,

    How do i put a PrimaryKey Value i selected in a listbox(Listbox contains records in form 1) in form 2 and put it in a field in a form 2?

    I have two tables : addnewborrower(One) and documents(Many) and they have a one to many relationship. I arldy established the relationship in the relationship window and the addnewborrower primary key is the foreignkey in documents which i have named BorrowerSerialNoFK.



    In my documents form, i have this listbox which shows records from addnewborrower. I want the user to select a record and then the selected record would give my foreignkey,BorrowerSerialNoFK, the value of the record ID which was selected.

    I have tried giving control source of my listbox as BorrowerSerialNoFK but then i cant select anything.I also tried giving the selected listbox value to a text box in the same form but i dont know how to refer this textbox to my field BorrowerSerialNoFK.Any idea how to solve this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You refer to form1 and form2. Is this a form/subform arrangement? What is the RecordSource for each form? Which is the main and which is subform?
    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
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76
    No in this case its a form to form arrangement. Please take a look at the attachment for a picture of my form. Form 1 recordsource is tblBorrowerDetails and Form 2 recordsource is tblRolesAndDocumentation. The top of the form is the listbox i was refering to. The bottom is all the details users would fill in. As you can see i set the textbox control source on the top left corner to my listbox. I set the listbox bound column to 3 so that the value will be equal to the borrowerserialno which is my third colum. However, this wont give the borrowerserialno that is IN my tblrolesanddocumentation table the value because the textbox controlsource is the listbox.
    I want to give the value to the borrowerserialno foreign key but whenever i put the bound textbox in my form its controlsource is borrowerserialno .

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    A form/subform arrangement would probably solve this issue.

    Still not sure what you want. Do you want to open form2 to a new record and populate serialno with the value from form1? This requires code (I use only VBA). By what I can see on the image, there is no interaction between these forms. No button on form1 to open form2.
    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: 7
    Last Post: 11-24-2014, 02:11 PM
  2. Deleting multiple records selected in a Listbox
    By ankitmehtta in forum Access
    Replies: 4
    Last Post: 11-08-2011, 01:20 PM
  3. Replies: 1
    Last Post: 07-28-2011, 08:34 AM
  4. Auto fill field upon New Record selected
    By NOTLguy in forum Programming
    Replies: 27
    Last Post: 12-05-2010, 05:12 PM
  5. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 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