+ Reply to Thread
Results 1 to 2 of 2

Adding record to table based on combo box selection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-26-2007
    MS-Off Ver
    2007
    Posts
    102

    Adding record to table based on combo box selection

    I am just getting my feet wet in Access. I have two tables and one form. In the form I have a combo box which holds selections from one table. I would like users to be able to choose a selection from the combo box the enter a entry in the following field. When clicking save I would like this field plus the ID of the item selected in the combo box stored in a table.

    I am attaching an example as it is far easier to show than explain. Any help would be greatly appreciated.

    Thank You!

    I am using Access 2007
    Attached Files Attached Files

  2. #2
    Forum Administrator ExlGuru's Avatar
    Join Date
    03-17-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: Adding record to table based on combo box selection

    Here is the code for adding a record to the table just try this may be helpful for you..

    Private Sub AddTaskBttn_Click()
    Dim Sn As String
    Sn = Me.cmbSerialNumber.Column(0)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Insert Into Tasklist( SerialNumber ) Select '" & Sn & "' As Expr;"
    DoCmd.SetWarnings True
    DoCmd.OpenForm "Task", , , "Dockets.SerialNumber =" & "'" & Me.cmbSerialNumber.Column(0) & "'", acFormAdd
    
    End Sub
    On the Form Open of Task I have the following code

    P
    rivate Sub Form_Open(Cancel As Integer)
    If Not IsNull(Me.OpenArgs) Then
    Sn.Value = Me.OpenArgs
    Me.Requery
    End If
    End Sub
    On the task form I have the following save and close button

    Private Sub FormClose_Click()
    On Error GoTo Err_FormClose_Click
    DoCmd.Save
    DoCmd.Close
    Exit_FormClose_Click:
    Exit Sub
    Err_FormClose_Click:
    MsgBox Err.Description
    Resume Exit_FormClose_Click
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1