?
Solved

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

Posted on 2016-10-18
31
Medium Priority
?
99 Views
Last Modified: 2016-10-19
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!
0
Comment
Question by:Dustin Stanley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 18
  • 12
31 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849229
Is the form bound to the table and the text box
 bound to a field in the table..
0
 

Author Comment

by:Dustin Stanley
ID: 41849235
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.
0
 

Author Comment

by:Dustin Stanley
ID: 41849238
[ProductImages].[ProductImageLocalPath]

Open in new window

This is what I tried in the control source
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849241
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
0
 

Author Comment

by:Dustin Stanley
ID: 41849244
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]?
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849251
If the form is unbound then you would use an Sql insert statement to add it to the table
0
 

Author Comment

by:Dustin Stanley
ID: 41849252
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
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849256
Youou are trying to insert data from the table into the table. Insert the form field text
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849257
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...
0
 

Author Comment

by:Dustin Stanley
ID: 41849263
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

0
 

Author Comment

by:Dustin Stanley
ID: 41849264
I will be back shortly within the hour. Thanks.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849265
if you look at the link i sent the syntax uses  the value keyword.  from implies  a  table
0
 

Author Comment

by:Dustin Stanley
ID: 41849267
Ok great sorry I didn't see that. It must had been while commenting.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41849269
Docmd.runsql "INSERT INTO ProductImages ( ProductImageLocalPath )
values ("  & Forms!TESTINGFORMBLANK!Text1 &  ")"

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

Author Comment

by:Dustin Stanley
ID: 41849288
Ok thanks. I will have to work on this in the morning.
0
 
LVL 21

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 1000 total points
ID: 41850217
Unbound form not needed and is extra work!

set the RecordSource of the form to your table.

make a textbox control for the path and file.
If you are using a path relative to the database location, a function, or equation, can be used to get the path and you can store just filename.

the ControlSource of an Image control can be an equation for path\filename, or a field with path\file in the table specified in form RecordSource.

then all you need is a Browse button to fill path\filename.

Busy today so someone else can help you with that

attached example:
ImageControl_120828_070721_Crystal__.zip
0
 

Author Comment

by:Dustin Stanley
ID: 41850478
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
0
 

Author Comment

by:Dustin Stanley
ID: 41850481
By the way I cant get the Zip to extract or open to view I just tried.
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 1000 total points
ID: 41850487
try some code in Form Current event:

e.g. yourimage.filepath = DLOOKUP("[ProductImages].[ProductImageLocalPath]","[ProductImages]","SKUID=" & SKUID)
yourimage.refresh
0
 

Author Comment

by:Dustin Stanley
ID: 41850497
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.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41850510
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)
0
 

Author Comment

by:Dustin Stanley
ID: 41850530
Ok I will see what I can do and get back with you. Thanks.
0
 

Author Comment

by:Dustin Stanley
ID: 41850577
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?
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41850598
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'
0
 

Author Comment

by:Dustin Stanley
ID: 41850647
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.
0
 

Author Comment

by:Dustin Stanley
ID: 41850657
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.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41850675
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)
0
 

Author Comment

by:Dustin Stanley
ID: 41850722
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.
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41850745
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?
0
 

Author Comment

by:Dustin Stanley
ID: 41850772
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.
0
 

Author Comment

by:Dustin Stanley
ID: 41850797
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

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question