Results 1 to 3 of 3
  1. #1
    antam is offline Novice
    Windows 10 Office 365
    Join Date
    May 2024
    Posts
    1

    error on the command with sub

    Dear Everyone,



    The sub c1tim() on command 4 of form as follows: => error
    Code:
    Sub c1tim(tablea As String, loai As String, x1 As Integer, tableb As String)
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim i As Integer
    
    ' Bc 1: Tìm giá tr? x1 trong các  C1 den C6 cua tablea
    Set db = CurrentDb()
    strSQL = "SELECT * FROM " & tablea & " WHERE Type = '" & loai & "'"
    Set rs = db.OpenRecordset(strSQL)
    
    ' Bc 2: Xóa du lieu tableb truoc khi dùng SQL vi?t các giá tr? tìm duoc ? bc1 vào tableb
    strSQL = "DELETE * FROM " & tableb
    db.Execute strSQL, dbFailOnError
    
    ' Bc 3: Sao chép toàn bo dòng tìm thay tu tablea vào tableb
    
    While Not rs.EOF
    For i = 1 To 7
    If rs.Fields("C" & i) = x1 Then
    strSQL = "INSERT INTO " & tableb & " SELECT * FROM " & tablea & " WHERE C" & i & " = " & x1 & " AND Type = '" & loai & "'"
    db.Execute strSQL, dbFailOnError
    
    Exit For
    End If
    Next i
    rs.MoveNext
    Wend
    
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    End Sub
    
    The sub to update data into table "daso455"
    Although query1 is ok.
    Pls find the attachment in the link below for your ref., thanks.
    https://drive.google.com/file/d/1NDc...usp=drive_link

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    put stop point on db.execute
    under the line: strSql =
    put : debug.print strSql

    copy the sql from the immediate window and paste into a query. run. it will show you the error.

    and you dont need db.execute, just use: docmd.runSql strSql

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,013
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Command button error
    By AndyRob1973 in forum Forms
    Replies: 10
    Last Post: 08-25-2021, 08:57 AM
  2. Error on insert into command
    By bubai in forum Access
    Replies: 17
    Last Post: 12-15-2020, 02:55 AM
  3. Command OpenRecordset leads to Error 48
    By Bo Hansson in forum Programming
    Replies: 4
    Last Post: 10-19-2017, 03:27 AM
  4. Network error and Command Button error
    By Sandra Williams in forum Access
    Replies: 1
    Last Post: 05-26-2013, 09:25 AM
  5. Replies: 0
    Last Post: 09-11-2006, 07:11 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
  •  
Other Forums: Microsoft Office Forums