Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    College Park, Maryland

    Red face Unanswered: How to create a .dbf file using VB 6.0

    hi people,
    can anyone help me creating a .dbf file using vb6.0. do i need to add a dll or what reference do i need to add so that i can create a .dbf file. im new w/ VFP.
    what i did now is i convert my excel report program to .dbf file but still it wont work. heres my code maybe u can revise this one.

    Function RunExcelReport()
    Dim rs2 As New ADODB.Recordset
    Dim oXL As Excel.Application
    Dim oWB As Excel.Workbook
    Dim oSheet As Excel.Worksheet
    Dim oRng As Excel.Range
    Dim nrow As Integer
    Dim SUM As Integer
    Dim DLYSALE As Double
    Dim pathz As String
    Dim filename As String

    SUM = 0
    nrow = 3

    Set rs2 = New ADODB.Recordset
    ' Create a connection to SQL.
    SQL2 = "SELECT * FROM SALES WHERE TRANDATE BETWEEN '" & datef & "' AND '" & datet & "'"

    rs2.Open SQL2, cConn, adOpenForwardOnly, adLockReadOnly

    ' Start Excel and get Application object.
    Set oXL = CreateObject("Excel.Application")
    oXL.Visible = True

    ' Get a new workbook.
    Set oWB = oXL.Workbooks.Add
    Set oSheet = oWB.ActiveSheet

    ' Add table headers going cell by cell.
    With oSheet
    .Cells(1, 1).Value = "TRANDATE"
    .Cells(1, 2).Value = "OLDGT"
    .Cells(1, 3).Value = "NEWGT"
    .Cells(1, 4).Value = "DLYSALE"
    .Cells(1, 5).Value = "TOTDISC"
    .Cells(1, 6).Value = "TOTREF"
    .Cells(1, 7).Value = "TOTCAN"
    .Cells(1, 8).Value = "VAT"
    .Cells(1, 9).Value = "TENTNAME"
    .Cells(1, 10).Value = "BEGINV"
    .Cells(1, 11).Value = "ENDINV"
    .Cells(1, 12).Value = "BEGOR"
    .Cells(1, 13).Value = "ENDOR"
    .Cells(1, 14).Value = "TRANCNT"
    .Cells(1, 15).Value = "LOCALTX"
    .Cells(1, 16).Value = "SERVCHARGE"
    .Cells(1, 17).Value = "NOTAXSALE"
    .Cells(1, 18).Value = "RAWGROSS"
    .Cells(1, 19).Value = "DLYLOCTAX"
    .Cells(1, 20).Value = "OTHERS"
    .Cells(1, 21).Value = "TERMNUM"

    End With

    ' Format A11 as bold, vertical alignment = center.
    With oSheet.Range("A1", "AA1")
    .Font.Bold = True
    .VerticalAlignment = xlVAlignCenter
    End With

    Do While rs2.EOF = False
    'inserting values in the cells
    With oSheet
    .Cells(nrow, 1).Value = rs2!TRANDATE
    .Cells(nrow, 2).Value = rs2!OLD_GT
    .Cells(nrow, 3).Value = rs2!NEW_GT
    .Cells(nrow, 4).Value = rs2!DLYSALE
    .Cells(nrow, 5).Value = rs2!TOTDISC
    .Cells(nrow, 6).Value = rs2!TOTREF
    .Cells(nrow, 7).Value = rs2!TOTCAN
    .Cells(nrow, 8).Value = rs2!VAT
    .Cells(nrow, 9).Value = rs2!TENTNAME
    .Cells(nrow, 10).Value = rs2!BEGINV
    .Cells(nrow, 11).Value = rs2!ENDINV
    .Cells(nrow, 12).Value = rs2!BEGOR
    .Cells(nrow, 13).Value = rs2!ENDOR
    .Cells(nrow, 14).Value = rs2!TRANCNT
    .Cells(nrow, 15).Value = rs2!LOCALTX
    .Cells(nrow, 16).Value = rs2!SERVCHARGE
    .Cells(nrow, 17).Value = rs2!NONTAXSALE
    .Cells(nrow, 18).Value = rs2!RAWGROSS
    .Cells(nrow, 19).Value = rs2!DLYLOCTAX
    .Cells(nrow, 20).Value = rs2!OTHERS
    .Cells(nrow, 21).Value = rs2!TERMNUM

    End With
    nrow = nrow + 1
    If rs2.EOF = True Then

    ' Fill date apply format.
    Set oRng = oSheet.Range(oSheet.Cells(3, 1), oSheet.Cells(nrow, 1))
    oRng.NumberFormat = "mm/dd/yyyy"
    'apply format.
    Set oRng = oSheet.Range(oSheet.Cells(3, 2), oSheet.Cells(nrow, 8))
    oRng.NumberFormat = "0.00"
    Set oRng = oSheet.Range(oSheet.Cells(3, 15), oSheet.Cells(nrow, 20))
    oRng.NumberFormat = "0.00"

    Set oRng = oSheet.Range(oSheet.Cells(3, 1), oSheet.Cells(nrow, 21))

    oXL.Visible = True
    oXL.UserControl = True
    filename = "ROY" & Month(datef) & Day(datef)
    pathz = App.Path & "\Report\" & filename & ".dbf"
    oSheet.SaveAs (pathz)

    Set rs2 = Nothing
    Set oRng = Nothing
    Set oSheet = Nothing
    Set oWB = Nothing
    Set oXL = Nothing

    Exit Function
    End If
    End Function

  2. #2
    Join Date
    Jul 2003
    Amsterdam, Nederland


    Quote Originally Posted by janlie87
    do i need to add a dll
    or what reference do i need to add
    so that i can create a .dbf file.
    im new w/ VFP.
    not sure /remember how Fox Pro works
    but in VB its
    Tools-> addin

    Then select .dbf dll see description behind
    Make sure it is loaded from start up
    see your Dll addin-manager in the menu for that

  3. #3
    Join Date
    Jun 2004
    Arizona, USA
    Also, keep in mind that most developers moved away from DAO to ADO years ago. (the last time I even looked at an app with DAO was 2000 or 2001...)
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts