Sam Summers
Registered User.
- Local time
- Today, 10:56
- Joined
- Sep 17, 2001
- Messages
- 939
Hi,
Now this worked before but for some reason it is throwing the error message - Runtime Error '13' Type mismatch
at this line:
I've set breakpoints and broken it down and checked the tables and associated forms but still get the same error?
Here is the code that was working.
I did change a forms data from a table to a query using the query builder from the properties window. Could this have done it?
Now this worked before but for some reason it is throwing the error message - Runtime Error '13' Type mismatch
at this line:
Code:
Set fldAttach = rstAttach.Fields("FileData")
I've set breakpoints and broken it down and checked the tables and associated forms but still get the same error?
Here is the code that was working.
Code:
Option Compare Database
Option Explicit
Private Sub AddCertBtn_Click()
Call AddAttachment("EmployeeCert", "CertImage", "EmployeeID", Me.EmployeeID, Me.CertID)
End Sub
Public Function AddAttachment(strTableName, strAttachField, strIDfield As String, i As Long, lngCertID As Long)
Dim fd As FileDialog
Dim oFD As Variant
Dim strFileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = False
.Title = "Choose File"
.InitialView = msoFileDialogViewDetails
.Show
For Each oFD In .SelectedItems
strFileName = oFD
Next oFD
On Error GoTo 0
End With
Set fd = Nothing
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, _
fldAttach As DAO.Field2
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset("SELECT " & strAttachField & " FROM " & strTableName & " where " & strIDfield & "= " & i & " AND CertID = " & lngCertID, dbOpenDynaset)
rstMain.Edit
Set rstAttach = rstMain(strAttachField).Value
rstAttach.AddNew
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.LoadFromFile strFileName
rstAttach.Update
rstAttach.Close
Set rstAttach = Nothing
rstMain.Update
rstMain.MoveNext
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing
End Function
I did change a forms data from a table to a query using the query builder from the properties window. Could this have done it?