error 3259 when adding a record with attachment (1 Viewer)

hansiepansie

New member
Local time
Today, 00:50
Joined
Aug 25, 2013
Messages
6
Hello Forum,


I want to add a record with attachment to a table in an access (2013) database.
If I ignore the attachment error everything works as it should, but as soon as I add the code for the attachment I receive error code 3259.

Code:
Private Sub add_tune()
 
   Dim dbtune As DAO.Database
   Dim rst_tune As DAO.Recordset
   Dim rst_tune_in As DAO.Recordset
   Dim rs_child As DAO.Recordset
 
 
   Set dbtune = CurrentDb
   Set rst_tune = dbtune.OpenRecordset("tbl_tune")
   Set rst_tune_in = dbtune.OpenRecordset("source_data")
   rst_tune_in.MoveFirst
 
 
   Do Until rst_tune_in.EOF = True
 
      rst_tune.AddNew
      rst_tune("t_title").Value = rst_tune_in("title")
 
      file_string = "G:\sibelius\scores\volksmuziek\dans\branl1.jpg"
 
      [COLOR=black]rst_tune.Fields("t_first_bars").LoadFromFile file_string[/COLOR]
 
      rst_tune("t_stamp").Value = Now()
      rst_tune.Update
 
      rst_tune_in.MoveNext
 
   Loop
 
   rst_tune.Close
   rst_tune_in.Close
 
   Set rst_tune = Nothing
   Set rst_tune_in = Nothing
End Sub

Since I have a dutch office version the error text (ongeldig veld gegevenstype) is in dutch, translated it means something like a data type mismatch.

t_first_bars is a field in the table tbl_tune . The field type is attachment.

What am I doing wrong ?
Your reply is highly appreciated,

Hans
 

hansiepansie

New member
Local time
Today, 00:50
Joined
Aug 25, 2013
Messages
6
Hi Forum,

I did the same test on another pc with the UK version of access 2010.

The error message I receive is

Run-time error 3259
Invalid field data type

Is it impossible to attach a .jpg file to a field with data type "attachment" ?

How should I change my code or my table setup to be able to attach a .jpg file to a specific field in a table?



Regards,
Hansiepansie
 

Poppa Smurf

Registered User.
Local time
Today, 17:50
Joined
Mar 21, 2008
Messages
448
The data type field to store the location of an attachment must be a Hyperlink.
 

hansiepansie

New member
Local time
Today, 00:50
Joined
Aug 25, 2013
Messages
6
Hello Poppa Smurf,

Tnx for your reply!!

The data type field to store the location of an attachment must be a Hyperlink.

OK, but I want the jpg itself to be included in the database and not only the location where to find it. That is why I created a field with data type "attachment".
Reason is that I want to be able to distribute the database to several people who might have another folder structure on their pc, therefor it is more easy to include the file in the db itself.

Can you help with some code to include the jpg in the db?

Best Regards,
Hansiepansie
 

Poppa Smurf

Registered User.
Local time
Today, 17:50
Joined
Mar 21, 2008
Messages
448
Sorry I can not help you.

Search the internet using "msaccess:storing jpg file in a table". This will give you some hits. If you store jpg in a database then the size of the database increase cinsiderably for each jpg.

Now if you use this line of code
file_string = "G:\sibelius\scores\volksmuziek\dans\branl1.jpg" it may be different for other users.
 

hansiepansie

New member
Local time
Today, 00:50
Joined
Aug 25, 2013
Messages
6
Good news!! Problem solved after some struggling :banghead:

This is the correct code

Code:
      rst_tune.AddNew
      rst_tune("t_title").Value = rst_tune_in("title")
 
      file_string = "G:\sibelius\scores\volksmuziek\dans\branl1.jpg"
 
      't_jpg is a field with data type "attachment" in table rst_tune
 
     Set rsPictures = rst_tune.Fields("t_jpg").Value
     'so rsPictures points to field t_jpg and is not a (visible?) table in the database   
 
   ' Add a new attachment.
     rsPictures.AddNew
 
     'FileData is a reserved word in Access and is not the name of a field in
    ' one of the user defined tables
      rsPictures.Fields("FileData").LoadFromFile file_string
      rsPictures.Update
 
      rst_tune.Update
 
Last edited:

hansiepansie

New member
Local time
Today, 00:50
Joined
Aug 25, 2013
Messages
6
Hi Poppa Smurf (nice name :) )

Now if you use this line of code
file_string = "G:\sibelius\scores\volksmuziek\dans\branl1.jpg" it may be different for other users.

I won't distribute this code. This code is only used to fill my table in the database once. I want to distribute the db after the filling job has finished.

Regards,
Hansiepansie
 

Users who are viewing this thread

Top Bottom