Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2016, 05:14 PM
carlandtina02 carlandtina02 is offline Using user form fields as folder path and file name Windows XP Using user form fields as folder path and file name Office 2010 64bit
Novice
Using user form fields as folder path and file name
 
Join Date: Mar 2016
Posts: 11
carlandtina02 is on a distinguished road
Default Using user form fields as folder path and file name

Hi Guys,



I have code that adds the value of a userform textbox as the file name,adds it to the folder path, then goes and pulls the file.

I need the code to use the folderpath (in the below code) open a folder based from the value in Text Box "TBM1Customer" then look for the file name and pull the file (in that order).

Any ideas would be much appreciated

Thanks
Carl
Code:
If Filename = vbNullString Then
  MsgBox "No Serial number available."
  Me.TBM1Serial.SetFocus
  Exit Sub
End If
Const strFldrPath As String = "C:\Documents and Settings\carl.walker\My Documents\Reports\"
Dim CurrentFile As String: CurrentFile = Dir(strFldrPath)
Dim FileFound As Boolean: FileFound = False
While CurrentFile <> vbNullString And FileFound = False
  If InStr(1, CurrentFile, Filename, vbTextCompare) > 0 Then
    ActiveWorkbook.FollowHyperlink (strFldrPath & CurrentFile)
    FileFound = True
  End If
  CurrentFile = Dir()
Wend
If FileFound = False Then
  MsgBox Title:="File Not Found", _
  Prompt:="File """ & Filename & """ not found in " & strFldrPath
End If
'Unload Me

Last edited by macropod; 04-10-2016 at 12:06 AM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 04-09-2016, 04:28 PM
BobBridges's Avatar
BobBridges BobBridges is offline Using user form fields as folder path and file name Windows 7 64bit Using user form fields as folder path and file name Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

I'm not sure I follow. You say you have the code, and then that you need it. There's a difference, I'm sure, between what you have and what you need, but they sound pretty similar.

Say you have the path in a variable called vPath, and you have the filename in a variable called vFile. You say you have the code that adds them together ("concatenates", I suppose you mean) and then pulls ("opens"?) the file. Now what you need, if I follow you, is code that "opens" the folder (but I'm not sure what that means) and then "looks for" the file. Since your program already has the file name, what exactly is it looking for?
Reply With Quote
  #3  
Old 04-10-2016, 12:16 AM
macropod's Avatar
macropod macropod is offline Using user form fields as folder path and file name Windows 7 64bit Using user form fields as folder path and file name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Presumably you want something like:
Code:
Filename = TBM1Customer.Text
If Dir(strFldrPath & Filename) <> "" Then
  Workbooks.Open Filename:=strCustFile
Else
  MsgBox Title:="File Not Found", _
  Prompt:="File """ & Filename & """ not found in " & strFldrPath
End If
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-15-2016, 01:47 PM
carlandtina02 carlandtina02 is offline Using user form fields as folder path and file name Windows XP Using user form fields as folder path and file name Office 2010 64bit
Novice
Using user form fields as folder path and file name
 
Join Date: Mar 2016
Posts: 11
carlandtina02 is on a distinguished road
Default

Hi Guys,

Sorry, I totally forgot about this post.
Its not needed now but thanks for getting in touch.

regards
Carl
Reply With Quote
Reply

Tags
hyperlink folder path, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
How can I get Outlook from one user to another w/o a .pst file (primary user on computer is corrupt) Tenmakk Outlook 0 03-01-2015 12:49 PM
How to find the path to the downloads folder when it is different for each user CatMan Excel Programming 2 12-07-2012 09:59 PM
Using user form fields as folder path and file name Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM
Using user form fields as folder path and file name Update Outlook but user path changed Ossie1972 Outlook 1 12-08-2010 08:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft