AS
VBA per Access
Operazioni sui record in una maschera
Spostamento fra record
Function recFirst()
DoCmd.GoToRecord acDataForm, , acFirst
End Function
Function recPrec()
DoCmd.GoToRecord acDataForm, , acPrevious
End Function
Function recSucc()
DoCmd.GoToRecord acDataForm, >, acNext
End Function
Function recLast()
DoCmd.GoToRecord acDataForm, , acLast
End Function
Nuovo record
Function recNew()
DoCmd.GoToRecord , , acNewRec
End Function
Elimina un record
Function recDelete(NomeMaschera As Form)
Dim V_Warning As String
If NomeMaschera.NewRecord = False Then
V_Warning = MsgBox("Cancellare la quotazione corrente?", 4)
If V_Warning = 6 Then
DoCmd.RunCommand acCmdDeleteRecord
End If
End If
End Function
OpenTable e OpenQuery
Aprire una tabella
Function openTbl(myTable As String)
DoCmd.OpenTable myTable
End Function
Aprire una query
Function openQry(myQuery As String)
DoCmd.OpenQuery myQuery
End Function
OpenForm e Close
Aprire una maschera
DoCmd.OpenForm "nome_maschera"
Chiudere una maschera
DoCmd.Close acForm, "nome_maschera", acSaveYes
'chiudi una maschera salvando le modifche
DoCmd.Close
'chiudi oggetto attivo
Contare i record di una query
Opzione con utilizzo della funzione DCount
If (DCount("*", "nome query") > 0) Then
'codice da eseguire se la query non resituisce un insieme vuoto
End If
Opzione con utilizzo dei DAO
Public Function conteggio_righe()
'funzione che restituisce il conteggio dei record di una query
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim nr_quotaz As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Count([Nome_campo]) AS Count_rows FROM nome_tabella", dbOpenDynaset)
If (IsNull(rst!Count_rows) = True) Then
conteggio_righe = 0
Else
conteggio_righe = rst!Count_rows
End If
rst.Close
db.Close
End Function
Aprire un report
DoCmd.OpenReport "rpr_offerta_dir", acViewReport
Chiudi il programma
Application.Quit