ciao NebbiaDB,
prova anche così.
lascia invariato il recordSource della maschera pratiche,
inserisci tre command buttons.
1)cmdPrevious per spostarsi al record precedente
2)cmdNext per spostarti al records successivo
- cmd nuovo per inserire un nuovo record.
comandi lo spostamento dei records solamente tramite command buttons, eliminando il selettore di records. ( a sviluppo ultimato)
Assegni il progressivo su salvataggio del record in automatico.
ci sarebbero ulteriori cosettine da migliorare, tipo abilitare i command buttons solo quando serve e/o necessario ad esempio...
Option Compare Database
Option Explicit
Dim strCaption As String
Private Sub cmdCaricaVerbale_Click()
If Me.Dirty Then
MsgBox "prima ci caricare il modello salva le modifiche", vbCritical, "informazione"
Exit Sub
End If
If Len(Me.oggetto & vbNullString) = 0 Then
MsgBox "oggetto non compilato", vbCritical, "informazione"
Exit Sub
End If
Dim strPathFile As String
strPathFile = cmdFileDialog()
If strPathFile <> vbNullString Then
Me.sm_verbali.Form.AllowAdditions = Not Me.sm_verbali.Form.AllowAdditions
Me.sm_verbali.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec
Dim intSlash As Integer
Dim strFile As String
Dim strPath As String
intSlash = InStrRev(strPathFile, "")
strFile = Right$(strPathFile, Len(strPathFile) - intSlash)
strPath = Left$(strPathFile, intSlash)
Me.sm_verbali!nome_file = strFile
Me.sm_verbali!myFolder = strPath
Me.sm_verbali.Form.AllowAdditions = Not Me.sm_verbali.Form.AllowAdditions
End If
End Sub
Private Sub cmdEdits_Click()
If Len(Me.oggetto & vbNullString) = 0 Then
MsgBox "oggetto non compilato", vbCritical, "informazione"
Exit Sub
End If
If Me.Dirty Then
If IsNull(Me.registro) Then
Me.registro = Format(Nz(Left(DMax("[registro]", "[elenco_pratiche]", "[registro] like '????/" & Format(Date, "yyyy") & "'"), 4), 0) + 1, "0000") & "/" & Format(Date, "yyyy")
End If
Me.Dirty = Not Me.Dirty
End If
Me.AllowAdditions = Not Me.AllowAdditions
Me.AllowEdits = Not Me.AllowEdits
strCaption = IIf(Me.AllowAdditions Or Me.AllowEdits, "Salva", "Modifica")
Me.cmdEdits.Caption = strCaption
End Sub
Private Sub cmdNext_Click()
moveRecords 2
End Sub
Private Sub cmdNuovo_Click()
If Not Me.AllowAdditions Or Me.AllowAdditions Then
Me.AllowAdditions = Not Me.AllowAdditions
Me.AllowEdits = Not Me.AllowEdits
End If
DoCmd.GoToRecord , , acNewRec
strCaption = IIf(Me.AllowAdditions Or Me.AllowEdits, "Salva", "Modifica")
Me.cmdEdits.Caption = strCaption
End Sub
Private Sub cmdPrevious_Click()
moveRecords 1
End Sub
Private Sub Comando16_Click()
DoCmd.OpenForm "elenco_modelli", acNormal, "", "", , acNormal
End Sub
Private Sub Comando28_Click()
If Len(Me.sm_verbali!nome_file & vbNullString) = 0 Then
MsgBox "nessun file selezionato o caricato!" & _
vbNewLine & " Carica o seleziona un file esistente!", vbCritical, "Attenzione"
Exit Sub
End If
Dim ret As Integer
ret = Shell("rundll32.exe url.dll,FileProtocolHandler " & Me.sm_verbali!myFolder & Me.sm_verbali!nome_file, vbNormalFocus)
'Dim objFSO As Object
' Dim objFolder As Object
' Dim objFile As Object
' Dim objSubfolder As Object
' Dim colSubfolders As Object
' Dim wshshell As Object
' Dim bln As Boolean
' Set wshshell = CreateObject("wscript.shell")
' Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set objFolder = objFSO.GetFolder("C:\Users\nebbia\Desktop\cartellafile")
' Set colSubfolders = objFolder.Subfolders
' On Error Resume Next
' For Each objSubfolder In colSubfolders
' For Each objFile In objSubfolder.Files
' wshshell.Run """" & objSubfolder.Path & "" & nome_file.Value & """"
' If Err.Number = 0 Then
' bln = True
' Exit For
' End If
' Err.Number = 0
' Next
' Next
' If bln = False Then
' MsgBox "File non trovato"
' End If
' Set wshshell = Nothing
' Set objSubfolder = Nothing
' Set colSubfolders = Nothing
' Set objFile = Nothing
' Set objFolder = Nothing
' Set objFSO = Nothing
End Sub
Sub moveRecords(ByVal moveType As Integer)
On Error GoTo errorHandler
If Me.AllowAdditions Or Me.AllowEdits Then
MsgBox "Maschera non salvata....!" & _
vbNewLine & "Salva i dati e procedi", vbInformation, "Avviso"
Exit Sub
End If
Select Case moveType
Case 1
DoCmd.GoToRecord , , acPrevious
Case 2
DoCmd.GoToRecord , , acNext
End Select
exitErrHandler:
Exit Sub
errorHandler:
With Err
MsgBox "ERR#" & .Number _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical
End With
Resume exitErrHandler
End Sub
ciao, Sandro.