Link to home
Create AccountLog in
Avatar of Dustin Stanley
Dustin Stanley

asked on

MS Access Image Control Get File Browse Function / Return File Path Of Image (How To Insert Path Into Table Instead of Unbound Text Box)?

This is the code I am using to get the file path to a unbound text box in MS Access.
Me!Text1 = GetFile_Browse

Open in new window

I really need to be able to store the file path into the Table I have called "ProductImages" Field "ProductImageLocalPath" as a new record.

When I try to bound the record source to the Table "ProductImages.ProductImageLocalPath" I get you can't assign a value to this object.

I know I need to have a bounded control and then go from that bounded control to a image control but I am not getting it!

Thank you!
Avatar of COACHMAN99

Is the form bound to the table and the text box
 bound to a field in the table..
Avatar of Dustin Stanley


No the form is not bound to the table currently. I have just made a small test form to get it correct and then I was going to put it on a official form. But either way I do  not think the control (Text box) will be bound either way.

When I make the textbox bound in the control source it gives the error.

Open in new window

This is what I tried in the control source
Im not sure I understand fully but before you bind a control source to a control you have to bind the form to a recordsource.Once the form is bound the table fields will be available to choose from
I know I am confusing. Even to myself. Is there any way to bind the control text box to the recordsource without it giving me an error?
Can I bind it in any other way besides a direct form made from the table?

Say I put a random text box on a random form how would I bind it to the recordsource [ProductImages].[ProductImageLocalPath]?
If the form is unbound then you would use an Sql insert statement to add it to the table
INSERT INTO ProductImages ( ProductImageLocalPath )
SELECT ProductImages.ProductImageLocalPath
FROM ProductImages;

Open in new window

Ok I will admit this is my weaker point but I was just thinking an Append Query would work. But it says I entered a operand without a operator
Youou are trying to insert data from the table into the table. Insert the form field text
I am using a very flaky wang chung tablet so having difficulty responding
Use Docmd.runsql "insert into table...
Its all good. When you say insert the form field text do you mean like this: (Also I know you will probably find my nonsense crazy)

INSERT INTO ProductImages ( ProductImageLocalPath )

Open in new window

I will be back shortly within the hour. Thanks.
if you look at the link i sent the syntax uses  the value keyword.  from implies  a  table
Ok great sorry I didn't see that. It must had been while commenting.
Docmd.runsql "INSERT INTO ProductImages ( ProductImageLocalPath )
values ("  & Forms!TESTINGFORMBLANK!Text1 &  ")"

i also have to go but i think you are very close.
Ok thanks. I will have to work on this in the morning.
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Ok the problem there is I am wanting to display the image on the main entry form and it is bounded to my SKUs Table.

I want the image control and button to be here on this form in the red box. I need a button to go retrieve file path store it in my [ProductImages].[ProductImageLocalPath] record and display it on the Skus Form.

I just got some time so I will try some different things. I will also look at the attachment.

Thank you All for the help!

User generated image
By the way I cant get the Zip to extract or open to view I just tried.
Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Ok maybe I am just overlooking something but with this event in the form Current....I see and get that it refreshes the Image Control Correct?

Are you speaking of the form being bounded to the table ProductImages or just a Unbound Image Control on any form?

I am trying to visualize it. Usually if I can visualize what you (Experts) are trying to do then I can configure it better.
this is to provide the image path to an unbound image control on any form, once the form is loaded (because you indicated you didn't want to bind this form and the main form to the table)
Ok I will see what I can do and get back with you. Thanks.
Ok So basically use a Dlookup for the image control Correct?

This will retrieve the filepath from the ProductImages Table and know what to display?
yes. if the stored path points to a valid image then it will display in the control once you have set the 'picture' property and refreshed the image (if it doesn't do it automatically)
the picture type should be 'linked'
Ok I think the real question is how can I get the function I am using to generate the file path into my ProductImages table field?

After that then the dlookup would work good.

I was just hoping there was a way to bind the text box to the table so when I generated the file path with the function and it went into the textbox it would then insert a new record into my table.
Me!Text1 = GetFile_Browse

Open in new window

This is what I was using for the command button.

How can I reference the table and field instead of the Text1 Text box?

I have figured out referencing forms and subforms just not tables yet.
when you say reference I assume you want to update the database?
if the textbox isn't bound then you cannot update the table field directly.
you have to use the code I provided above to run an insert statement.

if the data already exists then you would run an UPDATE statement (vs INSERT)
Ok I see and yes I want to insert a new record. But when I insert anything into the textbox control source I get "You can't assign a value to this object." after I click the command button browse to my file and select my image.
you don't insert into the textbox control source if it isn't bound - you insert into the 'text' property.

Me!Text1 = GetFile_Browse
then you assign the image 'picture' property = textbox.text

I get the horrible feeling we are going around in circles here?
I get the horrible feeling we are going around in circles here?
Maybe so with this technique. Ok I have been trying some things and I am getting somewhere. I will respond back when I have it working. Thanks.

you don't insert into the textbox control source  if it isn't bound - you insert into the 'text' property.

So the SQL statement doesn't go into the Control Source in the Property sheet of the Text box? That is where I thought it went.
Nevermind I am sorry.  I got it. I used a suborm in the main form to reference and and then I reference the image control back to the link. Thanks.

Private Sub Command119_Click()
Me!sbfrmProductImages.Form!ImageURL = GetFile_Browse
End Sub

Open in new window