Di seguito riporto il codice del Commandbutton 1 con cui effettuo l'inserimento
di dati tramite form. In esso ho iniziato a inserire un po' di codice per la gestione
degli errori.... solo che mi dà un errore..
- Codice: Seleziona tutto
Private Sub CommandButton2_Click()
If TextBox102 = "" Then
MsgBox "Devi inserire il numero del Documento"
TextBox102.SetFocus
Exit Sub
End If
Dim lTuttiDati As Long
'Controllo che non vi siano TextBox senza dati e nel caso avverto l'utente e
'chiedo cosa vuole fare. Per fare ciò utilizzo la funzione fControlloDati,
If fControlloDati Then
lTuttiDati = MsgBox("Non tutte le TextBox contengoni dati. Proseguire?", _
vbYesNo + vbQuestion, _
"Inserimento dati")
If lTuttiDati = vbNo Then Exit Sub
End If
Dim irisposta As Integer
Dim dbl As Double
irisposta = MsgBox("Confermi la registrazione" _
& " di " & TextBox102.Value & " ?", vbYesNo)
If irisposta = vbYes Then
On Error Resume Next
Range("B1").Value = "-"
Range("B1").End(xlDown).Offset(1, 0).Select
ActiveCell.Value = TextBox102
ActiveCell.Offset(0, 1).Value = TextBox103
ActiveCell.Offset(0, 2).Value = TextBox104
ActiveCell.Offset(0, 3).Value = CDate(TextBox105)
ActiveCell.Offset(0, 4).Value = TextBox106
ActiveCell.Offset(0, 5).Value = TextBox107
ActiveCell.Offset(0, 6).Value = TextBox108
ActiveCell.Offset(0, 7).Value = CDate(TextBox109)
ActiveCell.Offset(0, 8).Value = TextBox110
ActiveCell.Offset(0, 9).Value = TextBox111
ActiveCell.Offset(0, 10).Value = TextBox112
ActiveCell.Offset(0, 11).Value = TextBox113
ActiveCell.Offset(0, 12).Value = TextBox114
ActiveCell.Offset(0, 13).Value = TextBox115
ActiveCell.Offset(0, 14).Value = TextBox116
ActiveCell.Offset(0, 15).Value = CDbl(TextBox201)
ActiveCell.Offset(0, 16).Value = CDbl(TextBox202)
ActiveCell.Offset(0, 17).Value = CDbl(TextBox203)
ActiveCell.Offset(0, 18).Value = CDbl(TextBox204)
ActiveCell.Offset(0, 19).Value = CDbl(TextBox205)
ActiveCell.Offset(0, 20).Value = CDbl(TextBox206)
ActiveCell.Offset(0, 21).Value = CDbl(TextBox207)
ActiveCell.Offset(0, 22).Value = CDbl(TextBox208)
ActiveCell.Offset(0, 23).Value = CDbl(TextBox209)
ActiveCell.Offset(0, 24).Value = CDbl(TextBox210)
If Err.Number <> 0 Then
If Me.TextBox201.Text = "" Or .TextBox202.Text = "" Or _
.TextBox203.Text = "" Or .TextBox204.Text = "" Or _
.TextBox205.Text = "" Or .TextBox206.Text = "" Or _
.TextBox207.Text = "" Or .TextBox208.Text = "" Or _
.TextBox209.Text = "" Or .TextBox210.Text = "" Then
dbl = 0
Else
MsgBox "Operazione annullata, i dati inseriti devono essere numerici", _
vbOKOnly + vbCritical, _
"Inserimento dati"
Exit Sub
End If
End If
MsgBox "Registrazione eseguita!!"
TextBox102 = ""
TextBox103 = ""
TextBox104 = ""
TextBox105 = ""
TextBox106 = ""
TextBox107 = ""
TextBox108 = ""
TextBox109 = ""
TextBox110 = ""
TextBox111 = ""
TextBox112 = ""
TextBox113 = ""
TextBox114 = ""
TextBox115 = ""
TextBox116 = ""
TextBox201 = ""
TextBox202 = ""
TextBox203 = ""
TextBox204 = ""
TextBox205 = ""
TextBox206 = ""
TextBox207 = ""
TextBox208 = ""
TextBox209 = ""
TextBox210 = ""
End If
End Sub
Non appena provo a fare l'inserimento, lasciando appositamente le textbox che richiedono valori vuote, mi
viene riportato l'errore "Errore di compilazione: Riferimento non valido o non qualificato"
la riga in cui mi porta il debug è la seguente:
- Codice: Seleziona tutto
If Me.TextBox201.Text = "" Or .TextBox202.Text = "" Or _
Qualche suggerimento....