1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| Option Compare Database
Option Explicit
'---------------------------------------------------------------------------------------
' Crée un bitmap OLE uni de 1*1 pixel
'---------------------------------------------------------------------------------------
' pTable : Table contenant le champ OLE
' pField : Champ OLE à créer
' pWhere : Clause where indiquant quelle ligne mettre à jour
' pColor : Couleur (ex : vbRed ou RGB(255,0,0))
'---------------------------------------------------------------------------------------
Public Sub CreateOLEColor(pTable As String, pField As String, pWhere As String, pColor As Long)
Dim lOle As Variant
Dim lOLEByte() As Byte
Dim lCpt As Integer
Dim lr As Long, lb As Long, lg As Long
Dim ldb As DAO.Database
Dim lrs As DAO.Recordset
lOle = Array(21, 28, 47, 0, 2, 0, 0, 0, 13, 0, 14, _
0, 20, 0, 33, 0, 255, 255, 255, 255, 66, 105, _
116, 109, 97, 112, 32, 73, 109, 97, 103, 101, 0, _
80, 97, 105, 110, 116, 46, 80, 105, 99, 116, 117, _
114, 101, 0, 1, 5, 0, 0, 2, 0, 0, 0, 7, 0, _
0, 0, 80, 66, 114, 117, 115, 104, 0, 0, 0, 0, _
0, 0, 0, 0, 0, 64, 0, 0, 0, 66, 77, 58, 0, _
0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0, _
1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 24, 0, 0, 0, _
0, 0, 4, 0, 0, 0, 196, 14, 0, 0, 196, 14, _
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, _
0, 0, 0, 0, 0, 0, 0, 1, 5, 0, 0, 0, 0, _
0, 0, 130, 173, 5, 254)
ReDim lOLEByte(UBound(lOle))
For lCpt = 0 To UBound(lOle)
lOLEByte(lCpt) = CByte(lOle(lCpt))
Next
LongToRGB pColor, lr, lg, lb
lOLEByte(132) = CByte(lb)
lOLEByte(133) = CByte(lg)
lOLEByte(134) = CByte(lr)
Set ldb = CurrentDb
Set lrs = ldb.OpenRecordset("select [" & pField & "] from [" & pTable & "] where " & pWhere)
If Not lrs.EOF Then
lrs.Edit
lrs.Fields(pField).Value = lOLEByte
lrs.Update
lrs.Close
End If
Set lrs = Nothing
Set ldb = Nothing
End Sub
'---------------------------------------------------------------------------------------
' Conversion code couleur Long vers RGB
'---------------------------------------------------------------------------------------
' pLong : Numéro de la couleur
' pRed : Composante Rouge
' pGreen : Composante Verte
' pBlue : Composante Bleue
'---------------------------------------------------------------------------------------
Private Function LongToRGB(ByVal pLong As Long, pRed As Long, pGreen As Long, pBlue As Long) As Boolean
On Error GoTo Gestion_Erreurs:
pBlue = Int(pLong / 65536)
pGreen = Int((pLong - (65536 * pBlue)) / 256)
pRed = pLong - ((pBlue * 65536) + (pGreen * 256))
Gestion_Erreurs:
If Err.number = 0 Then LongToRGB = True ' Renvoie Vrai si pas d'erreur
End Function |
Partager