
read/write FoxPro 2.6 *and* Access 97 database files
Mark,
I kind of left a bunch of detail out. Maybe the whole SUB will make
more sense...
Note: Using Access 97 is no problem because it is a native in
VB5/VB6. There is a section in the online help that covers
"External Databases" that tells how to use .dbf and other structures.
EXAMPLE: ( not necessarily the cleanest code :-) )
Sub SumBalance(sMonthDay)
Dim curNTaxAmt As Currency
Dim curAmount As Currency
Dim curSumINV As Currency
Dim curSumTRS As Currency
Dim sZipFile As String
Dim sInvFile As String
Dim sTrsFile As String
Dim CRLF As String
Dim iDummy As Integer
Dim iCtr As Integer
Dim lNumCopied As Long
Screen.MousePointer = vbHourglass
frmMain.Hide
frmProgress.Show
frmProgress.Refresh 'double call forces complete display
frmProgress.Refresh
CRLF = Chr(13) & Chr(10) 'used as line separators in msgbox
sZipFile = sTemp & "AR02" & sMonthDay
sInvFile = sPath & "ARINV02"
sTrsFile = sPath & "ARTRS02"
'This sets the path to the data files...
Set dbsARINV = OpenDatabase(sPath, False, False, "Foxpro 2.6;")
'This creates the recordset for the dbf file...
Set rstARINV = dbsARINV.OpenRecordset("ARINV02")
'My second file that is to be used...do like first in setting up
Set dbsARTRS = OpenDatabase(sPath, False, False, "Foxpro 2.6;")
Set rstARTRS = dbsARTRS.OpenRecordset("ARTRS02")
'sum the appropriate fields in the ARINV and ARTRS databases
With rstARINV
.MoveFirst
iCtr = 0
frmProgress.pbar.Min = 0 'this all sets up min/max for
progress bars...
If .RecordCount < 14 Then 'so bar fills to end
frmProgress.pbar.Max = 14
Else
frmProgress.pbar.Max = .RecordCount
End If
While (Not .EOF) 'now stroll through dbf file on
desired field...
curSumINV = curSumINV + .Fields("FNTAXAMT")
iCtr = iCtr + 1
frmProgress.pbar.Value = iCtr
.MoveNext
Wend
End With
frmProgress.pbar.Value = 0
With rstARTRS
.MoveFirst
iCtr = 0
frmProgress.pbar.Min = 0
If .RecordCount < 14 Then 'so bar fills to end
frmProgress.pbar.Max = 14
Else
frmProgress.pbar.Max = .RecordCount
End If
While (Not .EOF)
curSumTRS = curSumTRS + .Fields("FAMOUNT")
iCtr = iCtr + 1
frmProgress.pbar.Value = iCtr
.MoveNext
Wend
If .RecordCount < 14 Then frmProgress.pbar.Value = 14
End With
frmProgress.Hide
Screen.MousePointer = vbDefault
If curSumINV <> curSumTRS Then
MsgBox "ERROR in Balances! ARINV02 = " & Format(curSumINV,
"$###,###.00") & _
" : ARTRS02 = " & Format(curSumTRS, "$###,###.00"),
vbCritical, _
GetBranchName()
Else
MsgBox "Balanced: ARINV02 = " & Format(curSumINV,
"$###,###.00") & _
" : ARTRS02 = " & Format(curSumTRS, "$###,###.00")
& CRLF & CRLF & _
"Record this balance." & CRLF, vbInformation, _
GetBranchName()
frmProgress.Show
frmProgress.Refresh 'double call forces complete display
frmProgress.Refresh
Screen.MousePointer = vbHourglass
'copy files to the temp directory
lNumCopied = rgbCopyFiles(sPath, sTemp, sFiles)
If lNumCopied > 0 Then
'use winzip to create a .zip file for transfer
MakeZipFile sZipFile
End If
frmProgress.Hide
Screen.MousePointer = vbDefault
End If
frmMain.Show
Set rstARINV = Nothing
Set rstARTRS = Nothing
Set dbsARINV = Nothing
Set dbsARTRS = Nothing
End Sub
On Thu, 10 Sep 1998 15:06:21 -0400, Mark Scott Smith
Quote:
>I need to read/write FoxPro 2.6 *and* Access 97 database files for an
>application I'm working on. Will VB (version?) provide the necessary
>capability? Is there any other development tool that might be a better
>fit?
>Thanks,
>Mark