Results 1 to 2 of 2
  1. #1
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66

    ComboBox - Input with Key issue

    2 databases:


    "tblCourse" DB linked to "Course Pack" DB via CourseID primary Key in "Course Pack". (Both numerical)
    "Course Pack" DB has two fields: CouseID / Course (text)

    "tblCourse" acquires the specific Course text and uses it in reporting.

    I have created a combo box for the purposes of finding and ultimately inputting new records into the "Course Pack / Course" DB record.

    I have this code which aids in this process. The problem is... the code is tied to the linkages which are numeric as opposed to placing the new record in "Course" which is TXT.

    Any help would be FANTASTIC!

    Code:
    Function Append2Table(cbo As ComboBox, NewData As Variant) As Integer
    On Error GoTo Err_Append2Table
    ' Purpose:   Append NotInList value to combo's recordset.
    ' Assumes:   ControlSource of combo has the same name as the foreign key field.
    ' Return:    acDataErrAdded if added, else acDataErrContinue
    ' Usage:     Add this line to the combo's NotInList event procedure:
    '                Response = Append2Table(Me.MyCombo, NewData)
        Dim rst As
        Dim sMsg As String
        Dim vField As Variant      ' Name of the field to append to.
    
        Append2Table = acDataErrContinue
        vField = cbo.ControlSource
        If Not (IsNull(vField) Or IsNull(NewData)) Then
            sMsg = "Do you wish to add the entry " & NewData & " for " & cbo.Name & "?"
            If MsgBox(sMsg, vbOKCancel + vbQuestion, "Add new value?") = vbOK Then
                Set rst = CurrentDb.    (cbo.RowSource)
                rst.AddNew
                    rst(vField) = NewData
                rst.Update
                rst.Close
                Append2Table = acDataErrAdded
            End If
        End If
    
    Exit_Append2Table:
        Set rst = Nothing
        Exit Function
    
    Err_Append2Table:
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation, "Append2Table()"
        Resume Exit_Append2Table
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    When you say 'DB', do you mean table?

    Don't understand table relationships nor purpose of tables. CoursePack is a 'lookup' table of courses? What is tblCourse for?

    If user types in a course name not in combobox list, you want to allow this to be added to CoursePack? This is an approach I've never seen.

    Is CourseID an autonumber field?

    Variable vField is set to the combobox ControlSource ([CourseID]) but don't you need the text field [Course]?

    Why is the Dim statement for rst incomplete? That should trigger compile error.
    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. ComboBox with input mask to display dropdown
    By wetsnow13 in forum Forms
    Replies: 2
    Last Post: 06-10-2013, 05:59 AM
  2. Replies: 7
    Last Post: 10-31-2011, 02:21 PM
  3. Input Mask Issue
    By bakkouz in forum Forms
    Replies: 2
    Last Post: 10-07-2011, 08:27 AM
  4. Criteria issue when using user input and > < ect
    By scotty562 in forum Queries
    Replies: 3
    Last Post: 11-11-2010, 11:08 AM
  5. Phone Input Mask issue
    By Huddle in forum Forms
    Replies: 4
    Last Post: 08-13-2010, 03:02 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