By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,377 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Adding Data to a Field

P: 56
I want to create a command button on a form that will populate a certain field in a certain table for that record with a hyperlink address (just the text) and add another field from that record to the string. For Example:

On Click, fill the field [DRAWING HYPERLINK] in the Table "ASSEMBLY" with W:\engineering\PRODUCT ENGINEERING\ASSEMBLY\PDF\ [field data from record].pdf

field data from record entitled [ASSY DOC]

The data in that field is A-2000-1

So the DRAWING HYPERLINK field in Table ASSEMBLY would have this data in it:

W:\engineering\PRODUCT ENGINEERING\ASSEMBLY\PDF\ A-2000-1.pdf

Just by Clicking the command button on the form.

I think this would be simple, but I am having trouble. Any help is greatly appreciated.

Thanks
Apr 17 '09 #1
Share this Question
Share on Google+
13 Replies


JustJim
Expert 100+
P: 407
@Desitech
Hi,
By "field data from record entitled [ASSY DOC]" do you mean that [ASSY DOC] is the name of a field in another table and that that field contains the data "A-2000-1" in the record which is showing on the form when you click the button you want to code?

If that is the case, I think you are correct that this should be fairly simple, but I'll wait for confirmation.

Jim
Apr 17 '09 #2

P: 56
Yes, but not in another table. The Form I am using is entitled FrmAssembly that is linked to a table entiled TblAssembly

[ASSY DOC] is the title of one of the fields in the same table

Fields in table looks like this:

DOCID ASSY DOC DESCRIPTION DATE BY DRAWINGHYPERLINK

Data in record looks like this:

DOCID =1
ASSY DOC= A-2000-1
DESCRIPTION = DH Assembly
DATE = 1/1/09
BY = DBT
DRAWING HYPERLINK = W:\engineering\PRODUCTENGINEERING\ASSEMBLY\PDF\ A-2000-1.pdf
Apr 17 '09 #3

JustJim
Expert 100+
P: 407
@Desitech
Even easier. Don't do it! If the text before and after the data in [ASSY DOC] is fixed, then it does not need to be stored in the table. Any time you need to use the full string you just build it up. eg.
Expand|Select|Wrap|Line Numbers
  1. strDrawing_Hyperlink = "W:\engineering\PRODUCTENGINEERING\ASSEMBLY\PDF\ " & Me.txtAssyDoc.Value & ".pdf"
assuming that txtAssyDoc is a text control on your form which holds tblAssembly.[ASSY DOC] for the required record.

Jim
Apr 17 '09 #4

P: 56
That must be close. I am not getting any error messages, but the command is not populating the DRAWING HYPERLINK field.
Apr 17 '09 #5

P: 56
I also need to populate the DRAWING HYPERLINK Field because I have another command button looking at the field to launch the hyperlink.
Apr 17 '09 #6

JustJim
Expert 100+
P: 407
@Desitech
It's not supposed to. You don't need that field. All the information is already either (1) stored in your table or (2) known and fixed.

When you need to use the fixed data and the stored data to do something (eg open the pdf file) you build the whole string by concatenating the known data with the stored data and then use that string to, again for example, open the file.

Jim
Apr 17 '09 #7

JustJim
Expert 100+
P: 407
@Desitech
We're a little out of synch here, but no worries!

Forget the first button and have the second button build the string I talked about before and use that string to execute the hyperlink.

Jim
Apr 17 '09 #8

P: 56
So are you saying with that line of code you sent, all I have to do is click on the command button and it will open that file I am looking for? If so, Then StrDrawing_Hyperlink must be wrong, because The Drawing Hyperlink fields are blank. The Code is not doing anything when I click on the command button.
Apr 17 '09 #9

JustJim
Expert 100+
P: 407
@Desitech
No, sorry, let's back up a little. The code in your button would be something like
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnYourButton_Click()
  2. Dim strHyperlink As String
  3. strHyperlink = "W:\engineering\PRODUCTENGINEERING\ASSEMBLY\PDF\ " & Me.txtAssyDoc.Value & ".pdf"
  4. Application.FollowHyperlink strHyperlink, , True
  5. End Sub
  6.  
The concept is that you don't have to store what ends up as the string strHyperlink in your table because you can build it from the data that is stored there.

Is that making sense? It's half past three in the morning here and I may well be gibbering!

Jim
Apr 17 '09 #10

P: 56
Yes that makes sence. But when I run the code, it doesn't like this line:

Application.FollowHyperlink strHyperlink, , True
Apr 17 '09 #11

JustJim
Expert 100+
P: 407
@Desitech
Add the following lines
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnYourButton_Click()
  2. Dim strHyperlink As String
  3. strHyperlink = "W:\engineering\PRODUCTENGINEERING\ASSEMBLY\PDF\ " & Me.txtAssyDoc.Value & ".pdf"
  4.  
  5. Debug.Print strHyperlink
  6. Stop
  7.  
  8. Application.FollowHyperlink strHyperlink, , True
  9. End Sub
Now when you click on the button, the code will stop after it has printed the value of strHyperlink to the Immediate Window (if you can't see the Immediate Window down the bottom of the Visual Basic window, either press <Ctrl>-G or click on View --> Immediate Window).

Check the value of strHyperlink as it is printed in the Immediate Window. I suspect that
A) there is an extra space in there between PDF\ and the value. I wasn't sure if you meant it to be a space, or
B) the whole string is not a "followable" hyperlink, and if you want to open a .pdf file, we have to do it another way. I'll think on that for a while.

Jim
Apr 17 '09 #12

P: 56
Yes...That's all it was was a space....It work...Ya Hooo!!!!!!

THANKS FOR ALL YOUR HELP !!!!
Apr 17 '09 #13

JustJim
Expert 100+
P: 407
@Desitech
Absolutely my pleasure. Moral of the story - don't store stuff you don't need to!

Have a good weekend

Jim

eta: I've still got it!
Apr 17 '09 #14

Post your reply

Sign in to post your reply or Sign up for a free account.