patriciaxxx
Programmer
I have the following code which I run form a button on a form which simply calls the InsertBLOB function. The forms record source is set to the table tblBlob.
Problem 1
I would like to include a count of the number of new records added which could simply be displayed in a msgbox which displays after the code has run
Problem 2
Once the code has run the form does not update to show the records added. I have tried putting Requery on all the forms events but it does not work. The only way I can make Requery work is by adding a button with it and running it on demand. But I need the form to Requery itself properyly.
Function InsertBLOB(varFileName As Variant) As Boolean
'Inserts BLOB to file from table tblBLOB
On Error GoTo CloseUp
Dim objStream As Object 'ADODB.Stream
Dim objCmd As Object 'ADODB.Command
Dim varFileBinary
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.LoadFromFile varFileName
varFileBinary = objStream.Read
objStream.Close
Set objStream = Nothing
Dim conn As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.path & "\" & CurrentProject.Name
Set myRecordset = New ADODB.Recordset
With myRecordset
.Open "Select * from tblBlob", _
strConn, adOpenKeyset, adLockOptimistic
.AddNew
!FileName = Left(Mid(varFileName, InStrRev(varFileName, "\") + 1), InStrRev(Mid(varFileName, InStrRev(varFileName, "\") + 1), ".") - 1)
!FileExt = Right(varFileName, Len(varFileName) - InStrRev(varFileName, "."))
!Blob = varFileBinary
.MoveFirst
.Close
End With
Set myRecordset = Nothing
Set conn = Nothing
InsertBLOB = True
CloseUp:
On Error Resume Next
Set objStream = Nothing
Set objCmd = Nothing
End Function
Problem 1
I would like to include a count of the number of new records added which could simply be displayed in a msgbox which displays after the code has run
Problem 2
Once the code has run the form does not update to show the records added. I have tried putting Requery on all the forms events but it does not work. The only way I can make Requery work is by adding a button with it and running it on demand. But I need the form to Requery itself properyly.
Function InsertBLOB(varFileName As Variant) As Boolean
'Inserts BLOB to file from table tblBLOB
On Error GoTo CloseUp
Dim objStream As Object 'ADODB.Stream
Dim objCmd As Object 'ADODB.Command
Dim varFileBinary
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.LoadFromFile varFileName
varFileBinary = objStream.Read
objStream.Close
Set objStream = Nothing
Dim conn As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.path & "\" & CurrentProject.Name
Set myRecordset = New ADODB.Recordset
With myRecordset
.Open "Select * from tblBlob", _
strConn, adOpenKeyset, adLockOptimistic
.AddNew
!FileName = Left(Mid(varFileName, InStrRev(varFileName, "\") + 1), InStrRev(Mid(varFileName, InStrRev(varFileName, "\") + 1), ".") - 1)
!FileExt = Right(varFileName, Len(varFileName) - InStrRev(varFileName, "."))
!Blob = varFileBinary
.MoveFirst
.Close
End With
Set myRecordset = Nothing
Set conn = Nothing
InsertBLOB = True
CloseUp:
On Error Resume Next
Set objStream = Nothing
Set objCmd = Nothing
End Function