Option Explicit
'attiva la Command Room
Private Sub Workbook_Open()
Sheets("CmdRoom").Activate
End Sub
'indica al combobox di input dove sono i dati per l'elenco a discesa
'es. Range Tipo nel foglio List
'acquisendo i dati dal foglio List dove ogni colonna ha definito il Nome e nel nome usa la formula: =SCARTO(LIST!$B$1;1;0;CONTA.VALORI(List!$B:$B)-1;1)
Sub UserForm_Initialize()
Load frmInput
Dim aCell As Range
For Each aCell In Range("Tipo")
cmbTipoVeicolo.AddItem (aCell.Value)
Next
For Each aCell In Range("Ora")
cmbOra.AddItem (aCell.Value)
Next
For Each aCell In Range("LuogoRecupero")
cmbLuogo.AddItem (aCell.Value)
Next
For Each aCell In Range("Trasporto")
cmbTrasporto.AddItem (aCell.Value)
Next
For Each aCell In Range("ComandoOperante")
cmbComando.AddItem (aCell.Value)
Next
For Each aCell In Range("Città")
cmbCittà.AddItem (aCell.Value)
Next
For Each aCell In Range("Autista")
cmbAutista.AddItem (aCell.Value)
Next
For Each aCell In Range("TipoRecupero")
cmbTipoRecupero.AddItem (aCell.Value)
Next
For Each aCell In Range("Demolitore")
cmbDemolitore.AddItem (aCell.Value)
Next
'incrementa di 1 l'ultimo numero di registrazione
Me.txtRegistrazione.Value = Worksheets("Records").Cells(Rows.Count, 1).End(xlUp).Value + 1
End Sub
'gestisce l'elenco a discesa MULTIPLO dal foglio List per i combobox Tipo e MarcaModello
'TipoAll ha il suo nome,
'mentre MarcaModello, nel nome, utilizza la funzione Expand che prende entrambe le colonne
Private Sub cmbTipoVeicolo_Change()
Dim aCell As Range
Me.cmbMarcaModello.Clear
For Each aCell In Range("TipoAll")
If aCell.Value = cmbTipoVeicolo.Value Then
Me.cmbMarcaModello.AddItem (aCell.Offset(0, 1))
Else
End If
Next aCell
End Sub
'input dei dati nel foglio Records da textbox e combobox, click dal bottone di comando Submit
Private Sub btnSubmit_Click()
'va al foglio Records
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Records")
'crea una nuova riga sotto l'ultima utilizzata
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("B:B")) + 1
Dim obj As Control
'input dei valori derivanti dai box, i numeri sono le colonne in successione
ws.Cells(newRow, 1).Value = Me.txtRegistrazione.Value
ws.Cells(newRow, 2).Value = Me.cmbTipoVeicolo.Value
ws.Cells(newRow, 3).Value = Me.cmbMarcaModello.Value
ws.Cells(newRow, 4).Value = Me.txtTarga.Value
ws.Cells(newRow, 5).Value = Me.txtTelaio.Value
ws.Cells(newRow, 6).Value = Me.txtCognomeNome.Value
ws.Cells(newRow, 7).Value = Me.txtDataIntervento.Value
ws.Cells(newRow, 8).Value = Me.cmbOra.Value
ws.Cells(newRow, 9).Value = Me.cmbLuogo.Value
ws.Cells(newRow, 10).Value = Me.txtZona.Value
ws.Cells(newRow, 11).Value = Me.cmbTrasporto.Value
ws.Cells(newRow, 12).Value = Me.cmbComando.Value
ws.Cells(newRow, 13).Value = Me.cmbCittà.Value
ws.Cells(newRow, 14).Value = Me.cmbAutista.Value
ws.Cells(newRow, 15).Value = Me.cmbTipoRecupero.Value
ws.Cells(newRow, 16).Value = Me.txtCausa.Value
ws.Cells(newRow, 17).Value = Me.txtVerbale.Value
ws.Cells(newRow, 18).Value = Me.txtSIVES.Value
ws.Cells(newRow, 19).Value = Me.txtDataRitiro.Value
ws.Cells(newRow, 20).Value = Me.txtAutorizzato.Value
ws.Cells(newRow, 21).Value = Me.txtDocumento.Value
ws.Cells(newRow, 22).Value = Me.txtDataDemolizione.Value
ws.Cells(newRow, 23).Value = Me.cmbDemolitore.Value
ws.Cells(newRow, 24).Value = Me.txtRicevuta.Value
ws.Cells(newRow, 25).Value = Me.txtFattura.Value
ws.Cells(newRow, 26).Value = Me.txtDataFattura.Value
ws.Cells(newRow, 27).Value = Me.txtNote.Value
'dopo il Submit, cancella di dati dai box Text e Combo
For Each obj In Me.Controls
If TypeOf obj Is MSForms.TextBox Then
obj.Text = ""
End If
If TypeOf obj Is MSForms.Combobox Then
obj.Text = ""
End If
Next
End Sub
'click bottone di comando Close, cancella i dati dai box Text e Combo
Private Sub btnClose_Click()
Dim obj As Control
For Each obj In Me.Controls
If TypeOf obj Is MSForms.TextBox Then
obj.Text = ""
End If
If TypeOf obj Is MSForms.Combobox Then
obj.Text = ""
End If
Next
Unload frmInput
|