Public Function AddJPEGImageToDatabase(strPath As String, Optional ImageID As Long = -1) As Long Dim rec As New ADODB.Recordset Dim picStream As New ADODB.Stream Dim conn As ADODB.Connection Dim strSQL As String Dim Pic As StdPicture Set conn = GetADOConnectionObject strSQL = "SELECT * FROM dbo.ImageData WHERE ImageID = " & ImageID rec.Open strSQL, conn, adOpenDynamic, adLockOptimistic LoadThePicture: Set Pic = LoadPicture(strPath) With picStream .Mode = adModeReadWrite .Type = adTypeBinary .Open Call .LoadFromFile(strPath) .Position = 0 If ImageID = -1 Then rec.AddNew rec("ImageData") = .Read rec("ImageX") = (Pic.Width / 1000) * (567 / Screen.TwipsPerPixelX) rec("ImageY") = (Pic.Height / 1000) * (567 / Screen.TwipsPerPixelY) strPath = GetRightBit(strPath, "\") strPath = Replace(strPath, " ", "-") strPath = ReplaceIllegalKeystrokes(strPath, True, True) SetTheFileName: rec("ImageFileName") = strPath rec.Update .Close AddJPEGImageToDatabase = rec("ImageID") rec.Close Set rec = Nothing Set Pic = Nothing Set picStream = Nothing End With End Function
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: