Insert Records

  • I created ADP form.  The form is not base on the tableC. The FORM is base on VIEW and View linked to tableA and TableB. I want to add new information into tableC using Insert INTO.

     

    Private Sub Save_Click()

    Dim strSQL As String

    On Error GoTo ErrMsg

    strSQL = "INSERT INTO Call_Log (InOut) VALUES(" & Val([Forms]![call_logs_form]![Text1])

    CurrentProject.Connection.Execute strSQL, adAffectCurrent

    ErrMsg:

    If Err.Number > 0 Then

        MsgBox Err.Number & ":" & Err.Description, vbCritical

        End If

    End Sub

  • Couple of things, one minor, one major.

    Minor:  You can now use me.fieldname instead of the forms!...

    The major advantage is it's checked during design time and you don't have to type it as intellisense finds the field for you.

    Major(Maybe minor typing error):  You don't have a closing parenthesis, you need to add & ")" to the end of the strSQL line.  Depending on the value InOUt is needing, the val function might return the incorrect value.  I used Val for setting a bit column and it always returned false.  If you're looking for a date, use cdate, cstr for string, etc.

     

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply