ADO error adding to recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tetelestai
    New Member
    • Nov 2006
    • 34

    ADO error adding to recordset

    Getting a type mismatch error (-2147352571 (80020005)) on this line of code

    ![RecievedDate] = Format(Me.txtRe cDate, "\#mm\/dd\/yyyy\#")

    I can't find the error number refenced anywhere. Any hints or helps would be appriciated.

    I'm using Access 2007

    Here is more code:

    Code:
        Set rst = New ADODB.Recordset
        
        
        rst.Open "tblOrders", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        
        With rst
            .AddNew
            ![JobID] = """" & Me.txtJobID & """"
            ![JobSubID] = """" & Me.cboJobSubID & """"
            ![JobType] = """" & Me.cboJobType & """"
            ![Model] = """" & Me.cboModel & """"
            ![Lot] = """" & Me.txtLot & """"
            Debug.Print "#" & Me.txtRecDate & "#"
            Debug.Print Format(Me.txtRecDate, "\#mm\/dd\/yyyy\#")
            ![RecievedDate] = Format(Me.txtRecDate, "\#mm\/dd\/yyyy\#")
            Debug.Print "after date"
            ![CustomerID] = Me.cboCustomer.Column(0)
            .Update
        End With
        
        rst.Close
        Set rst = Nothing
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Tetelestai
    Getting a type mismatch error (-2147352571 (80020005)) on this line of code

    ![RecievedDate] = Format(Me.txtRe cDate, "\#mm\/dd\/yyyy\#")

    I can't find the error number refenced anywhere. Any hints or helps would be appriciated.

    I'm using Access 2007

    Here is more code:

    Code:
        Set rst = New ADODB.Recordset
        
        
        rst.Open "tblOrders", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        
        With rst
            .AddNew
            ![JobID] = """" & Me.txtJobID & """"
            ![JobSubID] = """" & Me.cboJobSubID & """"
            ![JobType] = """" & Me.cboJobType & """"
            ![Model] = """" & Me.cboModel & """"
            ![Lot] = """" & Me.txtLot & """"
            Debug.Print "#" & Me.txtRecDate & "#"
            Debug.Print Format(Me.txtRecDate, "\#mm\/dd\/yyyy\#")
            ![RecievedDate] = Format(Me.txtRecDate, "\#mm\/dd\/yyyy\#")
            Debug.Print "after date"
            ![CustomerID] = Me.cboCustomer.Column(0)
            .Update
        End With
        
        rst.Close
        Set rst = Nothing
    You are asking a Date/Time Field ([ReceivedDate] within the underlying Recordset to store the formatted value Format(Me.txtRe cDate, "\#mm\/dd\/yyyy\#") which it cannot because of the inclusion of the # characters. Either convert the [ReceivedDate] Field to Text, or reformat it as such: Format(Me.txtRe cDate, "mm/dd/yyyy"). Hope this helps.

    Comment

    • pks00
      Recognized Expert Contributor
      • Oct 2006
      • 280

      #3
      Why dont u just do this, did this not work for you?
      It should recognise that txtRecDate is a datefield

      ![RecievedDate] = Me.txtRecDate


      Not sure about this

      ![RecievedDate] = "#" & Me.txtRecDate & "#"

      or

      ![RecievedDate] = CDATE(Me.txtRec Date)

      or long winded way

      ![RecievedDate] = dateserial( year(Me.txtRecD ate), month(Me.txtRec Date), day(Me.txtRecDa te))

      Comment

      • Tetelestai
        New Member
        • Nov 2006
        • 34

        #4
        Originally posted by pks00
        Why dont u just do this, did this not work for you?
        It should recognise that txtRecDate is a datefield

        ![RecievedDate] = Me.txtRecDate
        your correct that did work. Thanks. I knew it was something obvious.

        correct code below (for posterity)

        Code:
            Set rst = New ADODB.Recordset
            
            
            rst.Open "tblOrders", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
            With rst
                .AddNew
                ![JobID] = Me.txtJobID
                ![JobSubID] = Me.cboJobSubID
                ![JobType] = Me.cboJobType
                ![Model] = Me.cboModel
                ![Lot] = Me.txtLot
                ![RecievedDate] = Me.txtRecDate
                ![CustomerID] = Me.cboCustomer.Column(0)
                .Update
            End With
            
            rst.Close
            Set rst = Nothing

        Comment

        • pks00
          Recognized Expert Contributor
          • Oct 2006
          • 280

          #5
          Sometimes its easier than u think :)

          Comment

          Working...