Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.visual-basic > #20029

DB Access: Esportazione in Excel

X-Received by 2002:a05:620a:5221:b0:74e:a87:be3 with SMTP id dc33-20020a05620a522100b0074e0a870be3mr166219qkb.6.1681822405573; Tue, 18 Apr 2023 05:53:25 -0700 (PDT)
X-Received by 2002:a05:6830:184:b0:6a5:e61d:aa8e with SMTP id q4-20020a056830018400b006a5e61daa8emr638497ota.3.1681822405286; Tue, 18 Apr 2023 05:53:25 -0700 (PDT)
Path csiph.com!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups it.comp.lang.visual-basic
Date Tue, 18 Apr 2023 05:53:25 -0700 (PDT)
Injection-Info google-groups.googlegroups.com; posting-host=79.20.102.134; posting-account=F0nH9AoAAADAw4ovsJfWBkOqLlJca9ck
NNTP-Posting-Host 79.20.102.134
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <8e4dd23d-5078-4aa4-a306-bbb824ff5a65n@googlegroups.com> (permalink)
Subject DB Access: Esportazione in Excel
From valentina ferrari <ferr.valentina@gmail.com>
Injection-Date Tue, 18 Apr 2023 12:53:25 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
X-Received-Bytes 3376
Xref csiph.com it.comp.lang.visual-basic:20029

Show key headers only | View raw


Buongiorno,
Sto usando un DB in access nel quale c'è la possibilità di esportare in Excel su un file esistente.
Fino adesso mi  serviva solo l'esportazione della tabella ingegneria, ma ora devo esportare anche quella relativa ai materiali.
Inserito c'è questo codice, di cui ho provato ad apportare delle modifiche per l'esportazione della seconda tabella Materiali.

Private Sub prova_Click()
Dim xlApp As Object, xlSheet As Object
Dim rs As Recordset, ExcelTargetRange As Object, FieldNum As Integer
Dim i As Long, j As Long, k As Long, TblIng, TblMat As String
Dim ExcelFileName As String, ExcelSheetING, ExcelSheetMAT As String
Dim ExcelStartCell As String
intRisposta = MsgBox("Vuoi ESPORTARE TUTTI I DATI IN EXCEL?", vbInformation + vbYesNo)
If intRisposta = vbNo Then
Response = acDataErrDisplay
Exit Sub
End If

' INGEGNERIA
If intRisposta = vbYes Then
TblIng = "P_Ingegneria"
FieldNum = 22
ExcelFileName = "C:\Users\PC\Desktop\Costi.xlsx"
ExcelSheetING = "Ingegneria"
ExcelStartCell = "A14"

Set db = CurrentDb
Set rs = db.OpenRecordset(TblIng, dbOpenDynaset)
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(ExcelFileName)
Set ExcelTargetRange = xlSheet.Sheets(ExcelSheetING).Range(ExcelStartCell)
End If

  ' MATERIALI
If intRisposta = vbYes Then
Tblmat = "P_MAteriali"
FieldNum = 22
ExcelFileName = "C:\Users\PC\Desktop\Costi.xlsx"
ExcelSheetMat = "Materiali"
ExcelStartCell2 = "A14"

Set db = CurrentDb
Set rs = db.OpenRecordset(TblMat, dbOpenDynaset)
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(ExcelFileName)
Set ExcelTargetRange= xlSheet.Sheets(ExcelSheetMat).Range(ExcelStartCell2)
End If  

Do
k = k + 1
If IsEmpty(ExcelTargetRange(k, 1)) Then
Exit Do
End If
Loop

Do Until rs.EOF
For i = 1 To FieldNum
ExcelTargetRange(k, i) = rs.Fields(i - 1)
Next
k = k + 1
rs.MoveNext
Loop

xlSheet.Close SaveChanges:=True

End Sub

Mi dà errore però nella riga  "Set ExcelTargetRange= xlSheet.Sheets(ExcelSheetMat).Range(ExcelStartCell2)"  relativa ai materiali...Probabilmente devo inserire un altro rs all'inizio ma non so bene come...qualcuno mi può aiutare?
Grazie

Back to it.comp.lang.visual-basic | Previous | Next | Find similar


Thread

DB Access: Esportazione in Excel valentina ferrari <ferr.valentina@gmail.com> - 2023-04-18 05:53 -0700

csiph-web