[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

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!
0
Dustin Stanley
Asked:
Dustin Stanley
  • 18
  • 12
2 Solutions
 
COACHMAN99Commented:
Is the form bound to the table and the text box
 bound to a field in the table..
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
[ProductImages].[ProductImageLocalPath]

Open in new window

This is what I tried in the control source
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
If the form is unbound then you would use an Sql insert statement to add it to the table
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
Youou are trying to insert data from the table into the table. Insert the form field text
0
 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
I will be back shortly within the hour. Thanks.
0
 
COACHMAN99Commented:
if you look at the link i sent the syntax uses  the value keyword.  from implies  a  table
0
 
Dustin StanleyEntrepreneurAuthor Commented:
Ok great sorry I didn't see that. It must had been while commenting.
0
 
COACHMAN99Commented:
Docmd.runsql "INSERT INTO ProductImages ( ProductImageLocalPath )
values ("  & Forms!TESTINGFORMBLANK!Text1 &  ")"

i also have to go but i think you are very close.
0
 
Dustin StanleyEntrepreneurAuthor Commented:
Ok thanks. I will have to work on this in the morning.
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
By the way I cant get the Zip to extract or open to view I just tried.
0
 
COACHMAN99Commented:
try some code in Form Current event:

e.g. yourimage.filepath = DLOOKUP("[ProductImages].[ProductImageLocalPath]","[ProductImages]","SKUID=" & SKUID)
yourimage.refresh
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
Ok I will see what I can do and get back with you. Thanks.
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
COACHMAN99Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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
 
Dustin StanleyEntrepreneurAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 18
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now