DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Some idea pls!!!

  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Some idea pls!!!

    I'm on the process of developing a simple system in vb6 which has the capability of adding,deleting, retrieving and saving records..my database is access.. I've done with the 3 options except with saving.. I've already tried using this 2 way of coding:

    1st one goes lke this:

    On Error GoTo errhandler
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
    "Source=" & App.Path & "\dbttm.mdb;Persist Security Info=False"

    Set rsConn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    Set rs2 = New ADODB.Recordset

    If rsConn.State = adStateClosed Then
    rsConn.CursorLocation = adUseClient
    rsConn.Open strConn
    End If

    strSQL = "INSERT INTO tblttm (tnum, ctype, state, dreported, prior, tresolved, EOD, pdesc, ataken, notes, ename, uname, dept, petsa, eadd, lphone)"
    strSQL = strSQL & " Values ("
    strSQL = strSQL & "'" & Format(txttnum, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboctype)) & "',"
    strSQL = strSQL & "'" & Format(UCase(cbostate)) & "',"
    strSQL = strSQL & "'" & Format(txtdreport, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboprior)) & "',"
    strSQL = strSQL & "'" & Format(txttresolve, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboEON)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtpdesc)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtaTaken)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtNotes)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtname)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtuname)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtdept)) & "',"
    strSQL = strSQL & "'" & Format(txtpetsa, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(txteadd)) & "',"
    strSQL = strSQL & "'" & Format(txtlphone, "") & "')"

    rs.Open strSQL, rsConn, adOpenStatic, adLockBatchOptimistic, adCmdText
    rsConn.Execute strSQL
    MsgBox "Operation Succeeded..Record Saved!!..", vbInformation + vbOKOnly, Me.Caption
    Exit Sub

    errhandler:
    If Err.Number = -2147467259 Then
    MsgBox "Record Already Exists", vbExclamation + vbOKOnly, Me.Caption

    Else
    MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly + vbInformation, Me.Caption
    End If
    ERROR: SYNTAX ERROR IN SQL STATEMENT

    the 2nd one goes lyk this:

    Set rsConn = New ADODB.Connection
    rsConn.Open strConn
    Set rs = New ADODB.Recordset
    rs.Open "tblttm", rsConn, adOpenKeyset, adLockOptimistic
    rs.AddNew
    rs!tnum = txttnum.Text
    rs!ctype = cboctype.Text
    rs!State = cbostate.Text
    rs!dreported = txtdreport.Text
    rs!prior = cboprior.Text
    rs!tresolved = txttresolve.Text
    rs!EOD = cboEON.Text
    rs!pdesc = txtpdesc.Text
    rs!ataken = txtaTaken.Text
    rs!notes = txtNotes.Text
    rs!ename = txtname.Text
    rs!uname = txtuname.Text
    rs!uname = txtuname.Text
    rs!petsa = txtpetsa.Text
    rs!eadd = txteadd.Text
    rs!lphone = txtlphone.Text
    rs.Update
    rs.Close
    MsgBox "Operation Succeeded..Record Saved!!..", vbInformation + vbOKOnly, Me.Caption

    ERROR: TYPE MISMATCH


    Ive already used the first one when I developed a simple phonebook application in vb6...& it works...


    Pls...help me...I need some of ur suggestions that will help in this problem..tnx

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    First one
    Code:
    strSQL = "INSERT INTO tblttm (tnum, ctype, state, dreported, prior, tresolved, EOD, pdesc, ataken, notes, ename, uname, dept, petsa, eadd, lphone)"
    strSQL = strSQL & " Values ("
    strSQL = strSQL & "'" & Format(txttnum, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboctype)) & "',"
    strSQL = strSQL & "'" & Format(UCase(cbostate)) & "',"
    strSQL = strSQL & "'" & Format(txtdreport, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboprior)) & "',"
    strSQL = strSQL & "'" & Format(txttresolve, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(cboEON)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtpdesc)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtaTaken)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtNotes)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtname)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtuname)) & "',"
    strSQL = strSQL & "'" & Format(UCase(txtdept)) & "',"
    strSQL = strSQL & "'" & Format(txtpetsa, "") & "',"
    strSQL = strSQL & "'" & Format(UCase(txteadd)) & "',"
    strSQL = strSQL & "'" & Format(txtlphone, "") & "')"
    'add this line
    Debug.Print strSQL
    Post what is in the immediate window (after running this, click View/Immediate window.

    Second one, on what line does the error occur?

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2006, 08:06 PM
  2. Error while encrypting the xml file...pls help
    By sachinkataria in forum Java
    Replies: 3
    Last Post: 07-15-2006, 02:19 AM
  3. System.out.println() - help pls
    By kingvignesh in forum Java
    Replies: 17
    Last Post: 03-05-2006, 04:47 PM
  4. Replies: 1
    Last Post: 08-20-2000, 01:53 PM
  5. Replies: 1
    Last Post: 03-16-2000, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center