Hi, I have a database file named UnitPics that stores pictures of many units, and I have linked that table to the main database file.
Now, in the main database file I have created a button to export some data to Excel file output.
Here's the code:
Error message:Object variable or With block not set -> on picta=dlookup....
I am not sure how to do this, so I create these codes very simple. I want to display the picture with ID=1 from TblUnitPics in the excel file, and then save it. I am not sure if it is OLEObject, or whatever variable I should use. Can anyone direct me to the correct path?Thanks
Now, in the main database file I have created a button to export some data to Excel file output.
Here's the code:
Code:
Private Sub PictOne_Click()
Dim objExcel As Object
Dim objBook As Object
Dim objSheet As Object
Dim strFilter As String
Dim StrInputFileName As String
Dim myStrFilter As String
Dim strSaveFileName As String
Dim directory As String
Dim picta As OLEObject 'this is the variable to store the picture
Dim dbs As Database
Set dbs = CurrentDb
strFilter = ahtAddFilterItem(myStrFilter, "Excel Files (*.xlsx)", "*.xlsx")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.add
'Hide the workbook temporarily from the user
objExcel.Visible = False
objBook.SaveAs (strSaveFileName)
Set objSheet = objExcel.Worksheets("Sheet1")
picta = DLookup("UnitPic", "TblUnitPics", "ID=1")
objSheet.Cells("A1").Value = picta
objBook.Save
objExcel.Visible = True
Set objSheet = Nothing
objBook.Close
Set objBook = Nothing
End Sub
I am not sure how to do this, so I create these codes very simple. I want to display the picture with ID=1 from TblUnitPics in the excel file, and then save it. I am not sure if it is OLEObject, or whatever variable I should use. Can anyone direct me to the correct path?Thanks