Innanzitutto Vi informo che quanto esposto riguarda codice VBA di un file Access.
Sul codice qui sotto mi succede una cosa assurda, almeno per me, se ho sia la casella di controllo (si/no) non_imp, che la casella di testo lettera d'intento con la relativa data compilati allora nel file d'excel mi scrive la dichiarazione richiesta "operazione non imponibile, etc" se invece le caselle relative alla lettera d'intento sono vuote allora non scrive la dichiarazione sull'excel
Vi scrivo sotto tutto il codice per una comprensione di quanto enunciato.
In pratica ho due caselle di controllo una che si chiama TRATT dove se è attivata mi scrive una stringa nel file d'excel e questa funziona perfettamente, subito dopo ho il codice (IDENTICO) per la casella di controllo Non_Impo che ha il problema sopra descritto, immediatamente dopo ho il codice che mi controlla se le caselle di testo del numero lettera d'intento e la relativa data sono vuote o meno. Non riesco a capire come quest'ultima parte di codice possa influenzare quella precedente.
Grazie in anticipo
- Codice: Seleziona tutto
Private Sub fattura_Click()
' si dichiarano le variabili che conterranno gli oggetti Excel
Dim MyEx_Appl As Excel.Application 'Oggetto Applicazione Excel
Dim MyEx_WrkB As Excel.Workbook 'Oggetto Workbook
Dim MyEx_Wsht As Excel.Worksheet 'Oggetto Worksheet
Dim MyEx_Cell As Excel.Range 'Oggetto Range
' dichiariamo le variabili che hanno cella fissa
Dim CODICE_CLIENTE As String
Dim Ragione_Sociale As String
Dim INDIRIZZO_AZIENDA As String
Dim codice_postale As String 'Cap
Dim localita As String 'Città
Dim prov As String 'Provincia
Dim piva As String 'P_IVA
Dim codfisc As String 'Cod_Fisc
Dim fatt_num As String 'Numero_Fattura
Dim dat_fatt As String 'data_fattura
Dim soldi As String 'Pagamento
Dim carrelli As String 'CC
Dim extens As String 'Prolunghe
Dim schelv As String 'Pianali
Dim PESOTOTALE As Double
Dim totalefattura As Double
Dim totaleiva As Double
Dim totaleimponibili As Double
Dim sommaqta As Integer
Dim realimp As Double
Dim tratten As Double
Dim testo_trattenuta As String
Dim lettint As String
Dim datlett As String
'dichiaro le variabili che hanno riga mobile
Dim quantita As Integer
Dim descriz As String
Dim prezzounitario As Double
Dim primosconto As Byte
Dim secondosconto As Byte
Dim imponib As Double
'dichiaro e setto variabile per la sottomaschera e riga variabile
Dim rs As Recordset
Dim riga As Integer
Set rs = Me.Sottomaschera_RIGHE_FATTURA1.Form.Recordset
'Preleviamo i valori dalla maschera per le celle fisse
CODICE_CLIENTE = nz(cod_cliente.Value, "")
Ragione_Sociale = nz(Rag_Soc.Value, "")
INDIRIZZO_AZIENDA = nz(Indirizzo.Value, "")
codice_postale = nz(Cap.Value, "")
localita = nz(Città.Value, "")
prov = nz(Provincia.Value, "")
piva = nz(P_IVA.Value, "")
codfisc = nz(Cod_Fisc.Value, "")
fatt_num = nz(PROGRES_FAT.Value, "")
dat_fatt = nz(data_fattura.Value, "")
soldi = nz(Pagaments.Value, "")
carrelli = nz(CC.Value, "")
extens = nz(Prolunghe.Value, "")
schelv = nz(Pianali.Value, "")
PESOTOTALE = nz(Tot_Peso.Value, "")
totalefattura = nz(Tot_Fattura.Value, "")
totaleiva = nz(Tot_IVA.Value, "")
totaleimponibili = nz(Tot_Imponibile.Value, "")
sommaqta = nz(tot_piante.Value, "")
realimp = nz(VERO_IMPONIBILE.Value, "")
tratten = nz(TRATTENUTA.Value, "")
lettint = nz(NumLettIntent.Value, "")
datlett = nz(DataLettIntent.Value, "")
' - Creiamo una nuova applicazione excel;
Set MyEx_Appl = New Excel.Application
' - Aggiungiamo un nuovo workbook (generico)
Set MyEx_WrkB = MyEx_Appl.Workbooks.Open(Application.CurrentProject.Path & "\PROFORMA SCONTI.xls")
' - Prendiamo il primo foglio elettronico del workbook e lavoriamoci
Set MyEx_Wsht = MyEx_WrkB.Worksheets(1)
' Scrivo il valore
Set MyEx_Cell = MyEx_Wsht.Cells(12, 8)
MyEx_Cell.Value = CODICE_CLIENTE
Set MyEx_Cell = MyEx_Wsht.Cells(14, 4)
MyEx_Cell.Value = Ragione_Sociale
Set MyEx_Cell = MyEx_Wsht.Cells(16, 4)
MyEx_Cell.Value = INDIRIZZO_AZIENDA
Set MyEx_Cell = MyEx_Wsht.Cells(20, 4)
MyEx_Cell.Value = codice_postale
Set MyEx_Cell = MyEx_Wsht.Cells(19, 4)
MyEx_Cell.Value = localita
Set MyEx_Cell = MyEx_Wsht.Cells(19, 8)
MyEx_Cell.Value = prov
Set MyEx_Cell = MyEx_Wsht.Cells(21, 4)
MyEx_Cell.Value = piva
Set MyEx_Cell = MyEx_Wsht.Cells(22, 4)
MyEx_Cell.Value = codfisc
Set MyEx_Cell = MyEx_Wsht.Cells(3, 15)
MyEx_Cell.Value = fatt_num
Set MyEx_Cell = MyEx_Wsht.Cells(14, 15)
MyEx_Cell.Value = dat_fatt
Set MyEx_Cell = MyEx_Wsht.Cells(22, 13)
MyEx_Cell.Value = soldi
Set MyEx_Cell = MyEx_Wsht.Cells(79, 15)
MyEx_Cell.Value = carrelli
Set MyEx_Cell = MyEx_Wsht.Cells(81, 15)
MyEx_Cell.Value = extens
Set MyEx_Cell = MyEx_Wsht.Cells(81, 12)
MyEx_Cell.Value = schelv
Set MyEx_Cell = MyEx_Wsht.Cells(77, 6)
MyEx_Cell.Value = PESOTOTALE
Set MyEx_Cell = MyEx_Wsht.Cells(77, 15)
MyEx_Cell.Value = totalefattura
Set MyEx_Cell = MyEx_Wsht.Cells(75, 15)
MyEx_Cell.Value = totaleiva
Set MyEx_Cell = MyEx_Wsht.Cells(69, 15)
MyEx_Cell.Value = totaleimponibili
Set MyEx_Cell = MyEx_Wsht.Cells(76, 6)
MyEx_Cell.Value = sommaqta
Set MyEx_Cell = MyEx_Wsht.Cells(71, 15)
MyEx_Cell.Value = realimp
Set MyEx_Cell = MyEx_Wsht.Cells(70, 15)
MyEx_Cell.Value = tratten
[b]If TRATT = True Then
Set MyEx_Cell = MyEx_Wsht.Cells(70, 5)
MyEx_Cell.Value = "Trattenuta generale, giusto Art. 1 lettera B del Regolamento di Conferimento - 2,50%"
Else
MyEx_Cell.Value = ""
End If
If Non_Impo = True Then
Set MyEx_Cell = MyEx_Wsht.Cells(73, 10)
MyEx_Cell.Value = "OPERAZ. NON IMPONIBILE AI SENSI DELL'ART. 41 LEGGE 427 DEL 29/10/93."
Else
MyEx_Cell.Value = ""
End If
If lettint <> "" And datlett <> "" Then
Set MyEx_Cell = MyEx_Wsht.Cells(71, 3)
MyEx_Cell.Value = "Lettera d'intento Nr: " & lettint & "Del " & datlett
Else
MyEx_Cell.Value = ""
End If[/b]
'Preleviamo i valori dalla maschera per le celle con riga variabile
riga = 25
rs.MoveFirst
Do While Not rs.EOF
quantita = nz(rs.Fields("QTA").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 3)
MyEx_Cell.Value = quantita
' codice vecchio prima della function nz
'If rs.Fields("QTA").Value = 0 Then
'quantita = ""
'Else: quantita = rs.Fields("QTA").Value
'End If
'MyEx_Wsht.Cells(riga, 3).Value = quantita
descriz = nz(rs.Fields("DESCRIZIONEARTICOLO").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 4)
MyEx_Cell.Value = descriz
prezzounitario = nz(rs.Fields("PREZZOARTICOLO").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 14)
MyEx_Cell.Value = prezzounitario
primosconto = nz(rs.Fields("scontofinale1").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 12)
MyEx_Cell.Value = primosconto
secondosconto = nz(rs.Fields("scontofinale2").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 13)
MyEx_Cell.Value = secondosconto
imponib = nz(rs.Fields("Imponibile").Value, "")
Set MyEx_Cell = MyEx_Wsht.Cells(riga, 15)
MyEx_Cell.Value = imponib
riga = riga + 1
rs.MoveNext
Loop
' visualizziamo il foglio elettronico.
MyEx_Appl.Visible = True
Set MyEx_Appl = Nothing
Set MyEx_WrkB = Nothing
Set MyEx_Wsht = Nothing
Set MyEx_Cell = Nothing
End Sub