Syntax Error -Insert Into Statement

Keith

Registered User.
Local time
Today, 02:17
Joined
May 21, 2000
Messages
129
The following code works if Me.txtFrom is a date but not if it isn't. I copied and pasted the 'True' SQL string from the true case and removed the references to Member_From and Me.txtFrom putting it in the false case. If I run the procedure with no date in Me.txtFrom I get a message box 'Syntax Error in Insert Into Statement'. Any suggestions please.
Code:
Private Sub cmdSaveRecord_Click()
    Debug.Print "Date From "; Me.txtFrom.Value
    Dim AddSql As String
    
    Select Case IsDate(Me.txtFrom)

    Case True
        Debug.Print "I passed the True test.  BranchID "; Me.txtBranchUpdate, _
            "MemberID "; Me.txtMembID; "Date From "; Me.txtFrom
        AddSql = _
            "Insert into tblMemberBranchLink (BranchID,MemberID,Member_From) Values (" _
            & Me.txtBranchUpdate.Value & "," & Me.txtMembID.Value & ",#" & _
            Me.txtFrom.Value & "#)"

    Case False
        Debug.Print "I passed the false test  BranchID "; Me.txtBranchUpdate, _
            "MemberID "; Me.txtMembID
        AddSql = "Insert into tblMemberBranchLink (BranchID,MemberID,) Values (" _
            & Me.txtBranchUpdate.Value & "," & Me.txtMembID.Value & ")"

    End Select
    DoCmd.RunSQL AddSql
    Forms!frmMembers.Requery

End Sub
 
A DOH moment, reading my own post I saw a comma where there shouldn't be one. I'll have to go to specsavers. :)
 
when in trouble with sql syntax, always debug.print the sql-string. You can always paste it in the query designer and play until it is bug-free.
 
I knew the SQL statement was right but when I copied it and removed the date referances I left a comma in the string that shouldn't be there. But couldn't see it. :)
 

Users who are viewing this thread

Back
Top Bottom