Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    6

    Adding a record based on combo

    I am trying to add a record to a child database depending on what the user sees in the combo. Once the user determined a record should be added the AddTaskBttn is pressed.

    While the following function adds the serial number to the database when the form is filled out an error message tells me that the record can't be saved because the serial number is null. I have tried to use the doevents but to no avail.

    Private Sub AddTaskBttn_Click()


    Dim intX As Integer
    Dim Sn As String
    Sn = Me.CmbTaskList.Column(0)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Insert Into Tasklist( SerialNumber ) Select '" & Sn & "' As Expr;"
    DoCmd.SetWarnings True
    DoCmd.OpenForm "Task", , , "[TaskList.SerialNumber] =" & "'" & Me.cmbSerialNumber.Column(0) & "'", acFormAdd, acDialog
    For intX = 1 To 200
    Forms!Task!MailingDate_Label.Caption = "Doing something " & intX & " "
    DoEvents
    Next intX
    DoCmd.Close acForm, "Task"
    End Sub

  2. #2
    Join Date
    Feb 2009
    Posts
    6
    I have changed the code slightly. When the add task button is pressed the form is supposed to collect the rest of the information for the record. The form now opens and the serial number is added to the database however the rest of the field content on the form does not save

    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

    Private 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

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

Similar Threads

  1. Replies: 1
    Last Post: 02-02-2009, 05:52 AM
  2. Replies: 0
    Last Post: 08-17-2008, 12:19 PM
  3. if record not found through combo box
    By wasim_sono in forum Forms
    Replies: 2
    Last Post: 08-04-2008, 06:32 AM
  4. Need help - Record set based on a program variable
    By ericargent in forum Programming
    Replies: 1
    Last Post: 09-19-2007, 08:57 PM
  5. Adding a single record
    By kfoyil in forum Forms
    Replies: 2
    Last Post: 11-22-2006, 09:12 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