jgully
03-05-2009, 02:27 AM
Hello everyone.
I have a table with two fields, a SiteRef reference number and an OLE object (a BMP inserted using DBPix).
I also have a form with a DBPix imagecontrol and a button.
When I click the button i would like the access to run through all the records and load BMPs from a specified folder into the database. (i know linking is better etc etc, but this is what must be done...)
The BMPs are all named the same as the site ref. So i should be able to grab the folder name, the SiteRef and ".bmp", concatenate them and then insert them.
The trouble I'm having is in looping through the records. I am getting the SiteRef from a record set and then inserting via the image control on the form. For some reason it's pulling out the site ref from 10 rows down (and so the wrong image is being inserted).
Any ideas would be greatfully accepted!
Private Sub BtnInsertPlans_Click()
On Error Resume Next
Dim strFile As String
Dim strFullPath As String
Dim strFolderName As String
Dim DB As DAO.Database
Dim rst As DAO.Recordset
Dim SiteRef As String
' Display a 'Browse for folder' dialog - returns a folder path as a string.
strFolderName = BrowseFolder("Select folder to load images from")
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SiteForm")
' Check folderstring isnt empty
If Not IsEmpty(strFolderName) And Not strFolderName = "" Then
MsgBox strFolderName
rst.MoveFirst ' move recordset to first record
DoCmd.GoToRecord , , acFirst ' move form to first record
Do While Not rst.EOF
SiteRef = rst("Site ref")
strFullPath = strFolderName & "\" & SiteRef & ".bmp"
DBPixMain.ImageLoadFile (strFullPath)
rst.Update
DoCmd.GoToRecord , , acNext
rst.MoveNext
Loop
Else
MsgBox "Action cancelled: No folder selected."
End If
rst.Close
MsgBox "All done."
Finish:
End Sub
I have a table with two fields, a SiteRef reference number and an OLE object (a BMP inserted using DBPix).
I also have a form with a DBPix imagecontrol and a button.
When I click the button i would like the access to run through all the records and load BMPs from a specified folder into the database. (i know linking is better etc etc, but this is what must be done...)
The BMPs are all named the same as the site ref. So i should be able to grab the folder name, the SiteRef and ".bmp", concatenate them and then insert them.
The trouble I'm having is in looping through the records. I am getting the SiteRef from a record set and then inserting via the image control on the form. For some reason it's pulling out the site ref from 10 rows down (and so the wrong image is being inserted).
Any ideas would be greatfully accepted!
Private Sub BtnInsertPlans_Click()
On Error Resume Next
Dim strFile As String
Dim strFullPath As String
Dim strFolderName As String
Dim DB As DAO.Database
Dim rst As DAO.Recordset
Dim SiteRef As String
' Display a 'Browse for folder' dialog - returns a folder path as a string.
strFolderName = BrowseFolder("Select folder to load images from")
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SiteForm")
' Check folderstring isnt empty
If Not IsEmpty(strFolderName) And Not strFolderName = "" Then
MsgBox strFolderName
rst.MoveFirst ' move recordset to first record
DoCmd.GoToRecord , , acFirst ' move form to first record
Do While Not rst.EOF
SiteRef = rst("Site ref")
strFullPath = strFolderName & "\" & SiteRef & ".bmp"
DBPixMain.ImageLoadFile (strFullPath)
rst.Update
DoCmd.GoToRecord , , acNext
rst.MoveNext
Loop
Else
MsgBox "Action cancelled: No folder selected."
End If
rst.Close
MsgBox "All done."
Finish:
End Sub