Results 1 to 9 of 9
  1. #1
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171

    Writing the ID for a selected field on the form

    I have a basic form that is capturing a few fields. I need to write both values to the table which are based on the value of the corresponding comboboxes.
    For example, when the user selects a particular Manager from the combobox (cboManager), I need to write the corresponding TeamID and Manager for that selection to my Problem_Record tbl.

    tbl=Team has TeamID and Manager which are also fields in my Problem_Record tbl.
    column count 2


    column width 0.5";2";
    control Source = Manager
    Rowsource = SELECT Team.TeamID, Team.Manager FROM Team ORDER BY Team.Manager;

    Form is using Problem_Record as Record Source.

    How do I write the modify the code to capture both values for the Problem_Record tbl.

    Code:
    Private Sub cmdAddRecord_Click()
    Dim R As Recordset
    Set R = CurrentDb.OpenRecordset("SELECT * FROM [Problem_Record]")
    R.AddNew
    R![cboManager] = Me.Manager.Value               'Also need to capture the TeamId
    R![cboCOD] = Me.COD.Value
    R![cboFiscal_Year] = Me.Fiscal_Year.Value
    R![cboQuarter] = Me.Quarter.Value
    R![txtDate_Opened] = Me.Date_Opened.Value
    R![txtContract_Number] = Me.Contract_Number.Value
    R![cboCategory] = Me.Category.Value             ' Also need to capture the CategoryID
    R![cboProblem] = Me.Problem.Value                'Also need to capture the ProblemID
    R![cboStaff] = Me.Staff.Value                         ' Also need to capture the StaffID
    R![txtDescription] = Me.Description.Value
    R.Update
    R.Close
    Set R = Nothing
    'DoCmd.Close
    End Sub

    Just learning to use VBA and could use a little help!
    TIA!
    Last edited by orange; 03-29-2017 at 09:08 AM. Reason: adjusted code format

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can get the value of the second field with:

    Me.ComboName.Column(1)

    the column property is zero based, thus the 1 for the second column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Does table Problem_Record actually contain field names prefixed with "cbo" and "txt"? Normally those prefixes are used for controls on forms.
    And always, the receiving field is to the left of the "=".

  4. #4
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    R![cboManager] = Me.Manager.Value 'Also need to capture the TeamId
    To get the TeamID I used the following

    R![cboManager] = Me.Manager.Column(0) My TeamID is Column(0)

    It errored on this line. When I used the list that pops up after Me. it lets me select Manager but then it only give me .Value
    When I typed .Column(0) it errors.

  5. #5
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    cbo and txt are only control names on the form. They are not in the table that way.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    cbo and txt are only control names on the form. They are not in the table that way.
    Again, the receiving field is to the left of the "=".

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    R!Manager = Me.cboManager.Column(0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    Got it!!!

    Thanks to both of you. Getting more proficient by the day!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. writing a concatination field
    By Jen0dorf in forum Access
    Replies: 5
    Last Post: 03-30-2016, 10:48 AM
  2. Replies: 3
    Last Post: 12-03-2014, 01:40 PM
  3. Replies: 2
    Last Post: 09-22-2014, 11:11 AM
  4. Replies: 3
    Last Post: 01-17-2012, 01:04 PM
  5. Autofill a field once a Form is Selected from Switchboard
    By AccountingStudent in forum Forms
    Replies: 3
    Last Post: 09-13-2011, 11:26 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