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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems in DAO access using VB 2008

Status
Not open for further replies.

William_

Programmer
Jun 30, 2022
1
US
I am very belatedly updating a program to VB 2008 to store the path,name,extension,file size, and date in an Access DAO database. I wrote this in VB6 originally and it worked fine. My 2008 version also works fine except for one problem: When I try to transfer the file length to a variable .file_size (defined as long) in my Access database), I get the dreaded "A first chance exception of type 'System.OutOfMemoryException' occurred in Microsoft.VisualBasic.dll". I have determined the offending statement to be where I stuff a value into .file_size. If I comment this statement out, it runs without a hitch. Also if I assign a fixed value (such as .file_size=60892) it also runs fine. However, if I instead try to stuff the actual file value into .file_size (e.g., .file_size=FileLen(myfile)) I get this error. A debug statement preceding the stuff indicates the correct value has been returned from FileLen(myfile). Don't know what I am doing wrong. I realize a DAO database is obsolete, but I need a quick fix. Fyi, not a student, but an old user of VB6 for my research.

Addenda: If I set mySize to Long and give it a fixed value, it fails. If I define mySize as Object and give it a fixed value, it "works". If I set mySize to FileLen(myFile) it fails no matter how mySize is defined, even if I use CLng(FileLen(myFile)). Supposedly FileLen returns as long integer anyway.

Dim mySize As Long
(additional code)
For Each myfile In myfiles
n = n + 1
'Debug.Print(VB6.TabLayout(n, "File is:", myfile))
mypath = ""
myextension = ""
myfilename = ""
parse_file(myfile, mypath, myfilename, myextension)
'Now proceed to file database
With main_ref_file
On Error GoTo file_error
.AddNew()
.machine_ID = Trim(Me.Text1.Text)
.file_path = Trim(mypath)
.file_name = LCase(myfilename)
.file_extension = myextension
'On Error Resume Next
On Error GoTo Number_error
mySize = FileLen(myfile)
zSize = FileLen(myfile)
Debug.Print(zSize)
Debug.Print(VB6.TabLayout("File size is:", mySize))
If Math.Abs(zSize) < 2147483647 Then
.file_size = FileLen(myfile) 'throws an error
'.file_size = mySize 'throws an error unless mySize set to a literal value
'.file_size = 2147483646 'OK
Else
MsgBox("File length exceeds maximum: " & myfile)
End If
datestr = FileDateTime(myfile)
currdate = Today
'Debug.Print(VB6.TabLayout(n, "Present date is:", currdate))
'Debug.Print(VB6.TabLayout(n, "File date is:", datestr))
If IsDBNull(datestr) Or Trim(datestr) = "" Then
Debug.Print(VB6.TabLayout("Date is null: " & myfile))
datestr = "01/01/1980 12:00:00 PM"
.delete_flag = "A"
.file_date = CDate(datestr)
ElseIf currdate < CDate(datestr) Then
Debug.Print(VB6.TabLayout("bad date", currdate, datestr, CDate(datestr)))
.file_date = CDate(datestr)
Else
.file_date = CDate(datestr)
End If
.Update()
If 500 * (n \ 500) = n Then Me.Text = "Read record " & Str(n)
End With

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top