ACCESS記錄的刪除和讀寫

字號:

清空表記錄的方法
    1、CurrentDb().Execute \"delete * from 表名\"
    2、docmd.runsql \"SQL語句\"
    3,RunSQL \"Delete * From 表名\"
    確定所顯示的當(dāng)前記錄的記錄編號。
    下面的示例顯示如何使用
    Currentrecord 屬性來確定所顯示的當(dāng)前記錄的記錄編號。在通用過程 Currentformrecord 中將當(dāng)前記錄的編號值賦給變量 Lngrecordnum。
    Sub CurrentFormRecord(frm As Form)
    Dim lngrecordnum As Long
    lngrecordnum = frm.CurrentRecord \’CurrentRecord是當(dāng)前記錄號
    End Sub
    讀取最后一條記錄
    dlast(\"字段名\",\"表名\")
    在字段默認(rèn)值中用此函數(shù)能使該字段的新紀(jì)錄顯示上一條記錄該字段的值
    怎樣使窗體一打開就定位到指定記錄上
    定義了一個變量lngbh,要窗體打開時顯示ID=Lngbh的這條記錄。
    DoCmd.OpenForm \"formname\", acNormal, , \"ID =\" & LNGBH, acFormEdit, acWindowNormal
    如何在打開窗體時自動到相應(yīng)記錄
    用法:DoCmd.RunCommand acCmdRecordsGoToNew
    acCmdRecordsGoToFirst 移到第一條記錄
    acCmdRecordsGoToLast 移到最后一條記錄
    acCmdRecordsGoToNew 新增一條記錄
    acCmdRecordsGoToNext 移到下一條記錄
    acCmdRecordsGoToPrevious 移到上一條記錄
    判斷記錄的位置
    me.Recordset.AbsolutePosition = 0 \’第一條記錄
    me.Recordset.AbsolutePosition = me.Recordset.RecordCount -1 \’最后一條記錄
    me.Recordset.AbsolutePosition=-1 \’第一條記錄前 me.Recordset.bof=true
    me.Recordset.AbsolutePosition=me.Recordset.RecordCount \’最后一條記錄后 me.Recordset.eof=true
    me.Recordset.AbsolutePosition=n \’第n+1條記錄
    判斷是否為新增記錄
    me.newrecord=true
    me.newrecord=false
    VB語句刪除記錄:
    For I = 1 To 20
    SQL = \"Delete 訂單明細(xì)ID FROM 訂單明細(xì) Where 訂單明細(xì)ID=\" & I
    DoCmd.RunSQL SQL
    Next
    或:
    CurrentProject.Connection.Execute \"Delete * FROM要刪除記錄的表\"