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!
Microsoft AccessVisual Basic.NET

Avatar of undefined
Last Comment
Dustin Stanley

8/22/2022 - Mon
COACHMAN99

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

ASKER
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.
Dustin Stanley

ASKER
[ProductImages].[ProductImageLocalPath]

Open in new window

This is what I tried in the control source
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
COACHMAN99

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
Dustin Stanley

ASKER
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]?
COACHMAN99

If the form is unbound then you would use an Sql insert statement to add it to the table
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dustin Stanley

ASKER
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
COACHMAN99

Youou are trying to insert data from the table into the table. Insert the form field text
COACHMAN99

I am using a very flaky wang chung tablet so having difficulty responding
Seehttps://www.techonthenet.com/sql/insert.php
Use Docmd.runsql "insert into table...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Dustin Stanley

ASKER
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 )
SELECT Forms!TESTINGFORMBLANK!Text1
FROM Forms!TESTINGFORMBLANK;

Open in new window

Dustin Stanley

ASKER
I will be back shortly within the hour. Thanks.
COACHMAN99

if you look at the link i sent the syntax uses  the value keyword.  from implies  a  table
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dustin Stanley

ASKER
Ok great sorry I didn't see that. It must had been while commenting.
COACHMAN99

Docmd.runsql "INSERT INTO ProductImages ( ProductImageLocalPath )
values ("  & Forms!TESTINGFORMBLANK!Text1 &  ")"

i also have to go but i think you are very close.
Dustin Stanley

ASKER
Ok thanks. I will have to work on this in the morning.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
crystal (strive4peace) - Microsoft MVP, Access

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dustin Stanley

ASKER
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!

DB98.jpg
Dustin Stanley

ASKER
By the way I cant get the Zip to extract or open to view I just tried.
ASKER CERTIFIED SOLUTION
COACHMAN99

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dustin Stanley

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
COACHMAN99

Yes.
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)
Dustin Stanley

ASKER
Ok I will see what I can do and get back with you. Thanks.
Dustin Stanley

ASKER
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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
COACHMAN99

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'
Dustin Stanley

ASKER
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.
Dustin Stanley

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
COACHMAN99

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)
Dustin Stanley

ASKER
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.
COACHMAN99

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?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Dustin Stanley

ASKER
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.
Dustin Stanley

ASKER
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