Code:
Option Explicit
Dim bytData() As Byte ' Declarations
Private Sub Command3_Click()
On Error Resume Next
CommonDialog1.Filter = "All Files (*.*)|*.*|GIF Files (*.gif)|*.gif|JPEG Files (*.jpg)|*.jpg|Bitmap Files (*.bmp)|*.bmp"
CommonDialog1.ShowOpen
CommonDialog1.DialogTitle = "Select Picture" 'sets the title of it.
txtPicPath.Text = CommonDialog1.FileName
Open CommonDialog1.FileName For Binary As #1
ReDim bytData(FileLen(CommonDialog1.FileName))
Get #1, , bytData
Close #1
End Sub
Private Sub AddFaculty()
On Error GoTo ErrorDito
Dim strSQL As String
Dim adoCommand As ADODB.Command
Dim FacultyString As String
Set adoCommand = New ADODB.Command
FacultyString = "Faculty"
Debug.Print bytData
strSQL = "INSERT INTO tblFaculty (FacultyNumber,LastName,FirstName,MiddleName,Gender,UserType,Pass,Pic) VALUES(?,?,?,?,?,?,?,?)"
With adoCommand
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = strSQL
.Prepared = True
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 20, Text1.Text)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, Text2.Text)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, Text3.Text)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, Text4.Text)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 10, Combo1.Text)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 10, FacultyString)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, Text5.Text)
.Parameters.Append .CreateParameter(, adVarBinary, adParamInput, 65535, bytData)
.Execute , , adCmdText + adExecuteNoRecords 'the last two arguments makes the execution of the command faster
End With
Set adoCommand = Nothing
MsgBox "New record added", vbInformation
'requery the list
frmUserMenu.showlist
frmUserMenu.CountRecord
Unload Me
Exit Sub
ErrorDito:
MsgBox Err.Description, vbCritical
End Sub
The highlighted point the error