Results 1 to 4 of 4

Thread: [RESOLVED] Execute command will not update the database

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    48

    Resolved [RESOLVED] Execute command will not update the database

    Hello all and thanks in advance for any help you provide!Once again another bug came up. What the code does is depending what option the user checked update a certain table. The code i'm using is the following:

    Code:
    Private Sub Form_Load()
    
    Dim strSQL As String
    Dim update1 As String
    
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\warehouses.mdb"
    
    cn.Open
    strSQL = "SELECT * FROM warehouse3"
             Set rs = New ADODB.Recordset
    
            With rs
                 .Open strSQL, cn, adOpenForwardOnly, adLockPessimistic, adCmdText
    
    
    
           
    
                  If Not (.EOF And .BOF) Then
    
                    rs.MoveFirst    
    
                     Call FillFields      
    
                   End If
            End With
    End Sub
    And the button click:

    Code:
    Private Sub cmdAddNew_Click()
    
    Dim strSQL As String
    Dim update1 As String
    
               
        If Option3.Value = True Then
              If (Text1.Text = "" Or Text2.Text = "") Then
       
                  MsgBox "Insert Name,Code", vbExclamation, "Invalid Input"
       
                  Text1.SetFocus
                  
                  Exit Sub
       
              End If
       
             
      
              rs.AddNew
      
              rs.Fields("item_name") = Text1.Text
      
              rs.Fields("item_id") = Text2.Text
      
              rs.Fields("quantity") = IIf(Text3 = "", "0", Text3)
              
              rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4)
              
              rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5)
              
              rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7)
              
              rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3")
                
              rs.update
              
                  Call Sum
          ElseIf Option2.Value = True Then
          
          If (Text1.Text = "" Or Text2.Text = "") Then
       
                  MsgBox "Insert Name,Code", vbExclamation, "Invalid Input"
       
                  Text1.SetFocus
                  
                  Exit Sub
       
              End If
       
             
               update1 = "UPDATE Sum2 SET quantity= quantity - " & Val(Text2.Text) & " WHERE item_id='" & Text3.Text & "'"
               cn.Execute update1, , adCmdText + adExecuteNoRecords
               
    
      
              rs.AddNew
      
              rs.Fields("item_name") = Text1.Text
      
              rs.Fields("item_id") = Text2.Text
      
              rs.Fields("quantity") = IIf(Text3 = "", "0", Text3)
              
              rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4)
              
              rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5)
              
              rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7)
              
              rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3")
                          
              rs.update
              
              Call Sum
              
               
               
                   
    
    
        ElseIf Option1.Value = True Then
               
               If (Text1.Text = "" Or Text2.Text = "") Then
       
                  MsgBox " Insert Name,Code", vbExclamation, "Invalid Input"
       
                  Text1.SetFocus
                  
                  Exit Sub
       
              End If
               
               update1 = "UPDATE Sum1 SET quantity= quantity - " & Val(Text2.Text) & " WHERE item_id='" & Text3.Text & "'"
               cn.Execute update1, , adCmdText + adExecuteNoRecords
               
               
               
             
      
              rs.AddNew
      
              rs.Fields("item_name") = Text1.Text
      
              rs.Fields("item_id") = Text2.Text
      
              rs.Fields("quantity") = IIf(Text3 = "", "0", Text3)
              
              rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4)
              
              rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5)
              
              rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7)
              
              rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3")
                
              rs.update
              
              Call Sum
              
              
              
              
               
               
               
               
            End If
               
               
               
            
      
          End Sub
    With red are the update command that for some reason do not update the table!

  2. #2

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    48

    Re: Execute command will not update the database

    I have spent 3 hours trying to find out why the code isnt working and the problem was that the text boxes were upside down in the form...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Execute command will not update the database

    Quote Originally Posted by vagos7 View Post
    I have spent 3 hours trying to find out why the code isnt working and the problem was that the text boxes were upside down in the form...
    Upside down?

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    48

    Re: [RESOLVED] Execute command will not update the database

    Text3 was where text2 was supposed to be in the form.It thought it was text3 up and text2 down while it was the other way round. And the problem was that i was importing the wrong values because text2 was handling the item_id.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width