ciao Abitante,
setta una variabile oggetto che punti al database BE ed esegui le action queries :
Private Sub btnAzzeraContatoriTabelle_Click()
Dim dbs As dao.Database
Const strPathBe As String = "tuoFullPath" ' da peronsalizzare con nome completo db+estensione
Set dbs = OpenDatabase(strPathBe)
With dbs
.Execute "delete * from TblOperatori", &H80
.Execute "delete * from TblFornitori", &H80
.Execute "insert into
TblOperatori(id) values (0)", &H80 ' personalizza id con il nome della PK
.Execute "delete * from TblClienti", &H80
.Execute "insert into TblFornitori(id) values (0)", &H80 ' personalizza id con il nome della PK
.Execute "delete * from
TblFornitori", &H80
End With
dbs.Close
Set dbs = Nothing
VBA.MsgBox prompt:="Tabelle azzerate!", _
buttons:=vbInformation + vbOKOnly, _
Title:="Informazione"
End Sub
oppure se vuoi fare un po' il fanatico ;-) :
Private Sub btnAzzeraContatoriTabelle_Click()
On Error GoTo errHandler
Dim wrk As dao.Workspace
Dim dbs As dao.Database
Dim bool As Boolean
Const strPathBe As String = "tuoFullPath" ' da peronsalizzare con nome completo db+estensione
Set dbs = OpenDatabase(strPathBe)
Set wrk = CreateWorkspace("", "admin", "", 2) 'dbUseJet
Set dbs = wrk.OpenDatabase(strPathBe)
With wrk
.BeginTrans
With dbs
.Execute "delete * from TblOperatori", &H80
.Execute "delete * from TblFornitori", &H80
.Execute "insert into
TblOperatori(id) values (0)", &H80 ' personalizza id con il nome della PK
.Execute "delete * from TblClienti", &H80
.Execute "insert into
TblFornitori(id) values (0)", &H80 ' personalizza id con il nome della PK
.Execute "delete * from
TblFornitori", &H80
.Close
End With
.CommitTrans 1
.Close
bool = True
End With
ExitSub:
Set wrk = Nothing
Set dbs = Nothing
VBA.MsgBox prompt:="Tabelle azzerate!", _
buttons:=vbInformation + vbOKOnly, _
Title:="Informazione"
Exit Sub
errHandler:
With Err
If bool = 0 Then wrk.Rollback
MsgBox "ERR#" & CStr(.Number) _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical, cstrProc
End With
Resume ExitSub
End Sub
ciao e buona domenica.
Personalizza anche il nome delle tabelle per praticità ho ripreso quelle esposte dal codice e non dall'immagine.
Sandro.