Ciao a tutti, sono nuovo e mi scuso fin dall'inizio per eventuali miei errori sia di dicitura che sintassi relativamente al linguaggio di programmazione, in quanto sono neofita e tanto ignorante in materia (autodidatta ndr).
Quindi volevo sapere come mai non riesco a far funzionare un contatore di cui vi posto il modulo e routine di evento:
modulo:
Per ulteriori informazioni il mio db (Access) è già operativo e contiene già dei dati e pertanto il mio attuale campo contatore (NSRIF) non parte da zero.codice:Function fctAnnoNr(dte As Date) As String Dim db As DAO.Database Dim rst As DAO.Recordset Dim strSQL As String Set db = CurrentDb Set rst = db.OpenRecordset("datiIncarico", dbOpenDynaset, dbSeeChanges) With rst .MoveLast If .RecordCount = 1 Then 'Il primo record nella tabella fctAnnoNr = Right(Year(dte), 2) & "-0001" Exit Function End If .Close End With 'Nella tabella esistono record strSQL = "SELECT Year([DATAINCARICO]) AS Anno " _ & "FROM datiIncarico " _ & "WHERE Year([DATAINCARICO])=" & Year(dte) _ & " ORDER BY datiIncarico.DATAINCARICO DESC;" Set rst = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges) With rst .MoveLast fctAnnoNr = Right(Year(dte), 2) & "-" & Right("0000" & .RecordCount, 4) .Close db.Close End With Set rst = Nothing Set db = Nothing End Function routine: Private Sub DATA_INCARICO_AfterUpdate() If Me.NewRecord Or Right(Year(Me.DATA_INCARICO), 2) <> Left(Me.NS_RIF, 2) Then DoCmd.RunCommand acCmdSaveRecord Me.NS_RIF = fctAnnoNr(Me.DATA_INCARICO) Else DoCmd.RunCommand acCmdSaveRecord End If End Sub
Grazie e ciao
Farfisa

Rispondi quotando

