Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Access to Excel (In Particular Fields)

Status
Not open for further replies.

MHadden

Programmer
May 13, 2001
105
I need to export as follows:
[Name](in Access) = A:3 (in Excel)
[Address] (in Access) = B:5 (in Excel)
etc.
Is this possible? Can anyone help? Any help would be appreciated.
Thanks - in - Advance,
Michael MichaelHadden@BigFoot.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Hej Michael

First you need to open Excel:
Function OpenExcell(ExArk)
Dim MyXL As Object
Dim Svar
Const XL_NOTRUNNING As Long = 429
On Error GoTo err_OpenExcel_Click
Set MyXL = GetObject(, "Excel.Application")
If Not IsNull(ExArk) Then Workbooks.Open ExArk
If MyXL.Workbooks.Count = 0 Then
MyXL.Workbooks.Add
End If
MyXL.Application.Visible = True

exit_OpenExcel_Click:
Set MyXL = Nothing
Exit Function

err_OpenExcel_Click:
If Err = XL_NOTRUNNING Then
' Excel is not currently running.
Set MyXL = CreateObject("Excel.Application")
MyXL.Workbooks.Add
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description, , GetMsg("Sys_101")
End If
Resume exit_OpenExcel_Click
End Function

2nd you would want to drop your values into your worksheet
(Code start)
CellCount = 3
Set MyRe = MyDb.OpenRecordset(MySql, dbOpenDynaset)
If MyRe.RecordCount > 0 Then
Do While Not MyRe.EOF
If P_Model = 1 Then VareNr = MyRe!VareID
If P_Model = 2 Then VareNr = MyRe!Gruppe
If P_Model = 3 Then VareNr = MyRe!DebitorID
MyXL.ActiveWorkbook.ActiveSheet.Cells(CellCount, 1).Value = "'" & VareNr
If P_Model <> 3 Then MyXL.ActiveWorkbook.ActiveSheet.Cells(CellCount, 2).Value = MyRe!Tekst
If P_Model = 3 Then MyXL.ActiveWorkbook.ActiveSheet.Cells(CellCount, 2).Value = MyRe!Firma
CellCount = CellCount + 1
M_Row = CellCount
MyRe.MoveNext
Loop
End If
Dato_Akt = FraDato
Dato_Til = TilDato
ic = 1
Do While Dato_Akt <= Dato_Til
MyXL.ActiveWorkbook.ActiveSheet.Cells(1, ic + 2).NumberFormat = &quot;@&quot; 'Format cell to txt
MyXL.ActiveWorkbook.ActiveSheet.Cells(1, ic + 2).Value = Format(Dato_Akt, &quot;yymm&quot;)
ic = ic + 1
Dato_Akt = DateAdd(&quot;m&quot;, 1, Dato_Akt)
Loop
MyXL.ActiveWorkbook.ActiveSheet.Columns(&quot;B:B&quot;).EntireColumn.AutoFit
MyXL.ActiveWorkbook.ActiveSheet.Range(&quot;C3&quot;).Select

(Code end)

This last code is taken out of a module that I have compiles over several months. If you would like the module let me know

on Herman@wfbutik.dk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top