attachment (picture) in MS Access Form MySQL Database (1 Viewer)

budzprog

Registered User.
Local time
Yesterday, 17:22
Joined
Aug 5, 2011
Messages
11
hello...
i have an MS ACCESS Form (FE) and MySQL Database (BE)
my problem is when i attached a picture in a field only the name of the picture will appear (like: picture0001.jpeg) in the field...
how can i view the picture not the name of the picture..
when i run this in MS ACCESS Form (FE) and MS ACCESS Database the picture willl display in the field..
but when i coonect it in MySQL Database only the name of the picture will appear..
What will i do so that i can view the picture in MS ACCESS (FE) with MySQL Database..
tnx
 

GinaWhipp

AWF VIP
Local time
Yesterday, 20:22
Joined
Jun 21, 2011
Messages
5,899
Not seen that problem... Are you using an Image Control in the FE to display the picture?
 

budzprog

Registered User.
Local time
Yesterday, 17:22
Joined
Aug 5, 2011
Messages
11
im using an MS ACCESS FORM as Front End of MySQL Database..
 

GinaWhipp

AWF VIP
Local time
Yesterday, 20:22
Joined
Jun 21, 2011
Messages
5,899
On the form are you using an Image Control? In other words, what control are you using to display the image?
 

budzprog

Registered User.
Local time
Yesterday, 17:22
Joined
Aug 5, 2011
Messages
11
data type of my field is: attachment
 
Last edited:

budzprog

Registered User.
Local time
Yesterday, 17:22
Joined
Aug 5, 2011
Messages
11
do i have to recontract my MS ACCESS Form (front End)
do i have to change the field type (attachment)?
ok will check the link..
thanks
 
Last edited:

GinaWhipp

AWF VIP
Local time
Yesterday, 20:22
Joined
Jun 21, 2011
Messages
5,899
You need to check the link as you said you where going to... You will see you need an Image Control.
 

Max D

Registered User.
Local time
Yesterday, 17:22
Joined
Jul 3, 2009
Messages
91
As far as I know, Access 2007 doesn't support attachment field type for SQL-Server.

Or Access 2010 already does? :)
 

GinaWhipp

AWF VIP
Local time
Yesterday, 20:22
Joined
Jun 21, 2011
Messages
5,899
@Max D,

Not *Attachment* type field in the field... *Image Control* on the form.
 

kulmen98

New member
Local time
Today, 07:22
Joined
Jul 20, 2022
Messages
2
do i have to recontract my MS ACCESS Form (front End)
do i have to change the field type (attachment)?
ok will check the link..
thanks
Excuse me sir,i also have the same problem as mr budzfrog's problem, for the image display on microsoft access that i connect to the mysql database can't appear, and from @GinaWhipp link shared which part should i download,? thank you sir
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:22
Joined
May 7, 2009
Messages
19,248
here is the code i just tested:
Code:
'https://usefulgyaan.wordpress.com/2014/09/30/store-and-fetch-files-sql-server-tables/
'modified by arnelgp to accept variables as parameter and for MySQL
'To save a file in a table as binary
'
'Parameters:
'
' strServerName     = server name
' strDb             = database name
' tableName         = table that holds the image
' blobfield         = the field that holds the image
' strFilePath       = the image filename and location
' IsMySQL           = true or false, if you are using MySQL set this parameter to True
'
Sub SaveAsBinary( _
        ByVal strServerName As String, _
        ByVal strDB As String, _
        ByVal tableName As String, _
        ByVal blobField As String, _
        ByVal strFilePath As String, _
        Optional ByVal IsMySQL As Boolean = False)

    Dim adoStream               As Object
    Dim adoCmd                  As Object
    Dim adoCon                  As Object
    'Dim strFilePath             As String
    'Const strDB                 As String = ""  'Database name
    'Const strServerName         As String = ""  'Server Name
    
    Set adoCon = CreateObject("ADODB.Connection")
    Set adoStream = CreateObject("ADODB.Stream")
    Set adoCmd = CreateObject("ADODB.Command")
    
    'arnelgp
    Dim adoRecorset As Object
    Set adoRecorset = CreateObject("ADODB.Recordset")
    
    '--Open Connection to SQL server
    adoCon.CursorLocation = adUseClient
    'arnelgp
    If IsMySQL Then
        'change the UID (userid) and pwd (password)
        adoCon.Open "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=" & strServerName & ";DATABASE=" & strDB & ";UID=root;PWD=;OPTION=16427"
    Else
        adoCon.Open "Provider=SQLOLEDB;Data Source=" & strServerName & ";Initial Catalog = " & strDB & ";Integrated Security=SSPI;"
    End If
    '----
    
    'strFilePath = "C:\1.JPG" ' File to upload
    
    adoStream.Type = adTypeBinary
    adoStream.Open
    adoStream.LoadFromFile strFilePath 'It fails if file is open
        
    If Not IsMySQL Then
        With adoCmd
            '.CommandText = "INSERT INTO Employee VALUES (?,?)" ' Query
            .CommandText = "INSERT INTO [" & tableName & "] (" & blobField & ") VALUES (?)" ' Query
            .CommandType = adCmdText
            
            '---adding parameters
            '.Parameters.Append .CreateParameter("@Id", adInteger, adParamInput, 0, 1)
            .Parameters.Append .CreateParameter("@Image", adVarBinary, adParamInput, adoStream.Size, adoStream.Read)
            '---
        End With
        
        adoCmd.ActiveConnection = adoCon
        adoCmd.Execute
    
    Else
        adoRecorset.Open tableName, adoCon, adOpenKeyset, adLockPessimistic, adCmdTable
        With adoRecorset
            .AddNew
            .Fields(blobField) = adoStream.Read
            .Update
            .Close
        End With
        
    End If
    
    adoCon.Close
    
End Sub


'https://usefulgyaan.wordpress.com/2014/09/30/store-and-fetch-files-sql-server-tables/
'modified by arnelgp to accept variables as parameter and for MySQL
'To read binary stream from DB and save the same on system drive
'
'Parameters:
'
' strServerName     = server name
' strDb             = database name
' tableName         = table that holds the image
' pkName            = the primary key field name
' pkValue           = the value of the PK where the image is to be fetch
' blobfield         = the field that holds the image
' strFilePath       = the image filename and location
' IsMySQL           = true or false, if you are using MySQL set this parameter to True
'
Sub ReadBinary( _
        ByVal strServerName As String, _
        ByVal strDB As String, _
        ByVal tableName As String, _
        ByVal pkName As String, _
        ByVal pkValue As Long, _
        ByVal blobField As String, _
        ByVal strFilePath As String, _
        Optional ByVal IsMySQL As Boolean = False)

    
     Dim adoRs                  As Object
     Dim adoStream              As Object
     Dim adoCon                 As Object
     'Const strDB                As String = ""  'Database name
     'Const strServerName        As String = ""  'Server Name
      
    
     Set adoCon = CreateObject("ADODB.Connection")
     Set adoRs = CreateObject("ADODB.Recordset")
     Set adoStream = CreateObject("ADODB.Stream")
        
     '--Open Connection to SQL server
     adoCon.CursorLocation = adUseClient
    'arnelgp
    'not working on MySQL part!!!!!!!!!!
    If IsMySQL Then
        'change the UID (userid) and pwd (password)
        adoCon.Open "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=" & strServerName & ";DATABASE=" & strDB & ";UID=root;PWD=;OPTION=16427"
         adoRs.Open "SELECT " & blobField & "  FROM " & tableName & " WHERE " & pkName & " = " & pkValue & ";", adoCon, adOpenStatic, adLockOptimistic

    Else
        adoCon.Open "Provider=SQLOLEDB;Data Source=" & strServerName & ";Initial Catalog = " & strDB & ";Integrated Security=SSPI;"
         adoRs.Open "SELECT " & pkName & ", " & blobField & "  FROM " & tableName & " WHERE " & pkName & " = " & pkValue & ";", adoCon, adOpenStatic, adLockOptimistic
    End If
    adoStream.Type = adTypeBinary
    adoStream.Open
    adoStream.Write adoRs(blobField).Value    '.Value ' FieldName that contains binary data
    
    adoStream.SaveToFile strFilePath, adSaveCreateOverWrite
    
     '--
     adoRs.Close
     adoCon.Close

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:22
Joined
May 7, 2009
Messages
19,248
you need to actually work on it.
posting some snapshot may not help.
'not working on MySQL part!!!!!!!!!!
glad to say it is now working as i tested in MySQL community.
 

Users who are viewing this thread

Top Bottom