473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use a text value as a variable in VBA

Is it possible to have a text box on a form that can be referenced as a variable in a strpath command?

at the minute i have this in my module

strPath = "C:\Users\USER\Documents\Database Creations\CTR\"

what i would like is
strPath = "inputform.folderlocation.value"

this would mean the user wouldn't have to mess with code and i wouldn't have to fix issues in the future.

I have considered using browse to folder but this is only a sample, there are many other values that might need updating.

Below is the full code i am using, any questions or suggestions would be great!

Thanks

Expand|Select|Wrap|Line Numbers
  1. Function DoImport()
  2.  
  3.  
  4. Dim strPathFile As String, strFile As String, strPath As String
  5. Dim blnHasFieldNames As Boolean
  6. Dim intWorksheets As Integer
  7.  
  8. ' Replace 3 with the number of worksheets to be imported
  9. ' from each EXCEL file
  10. Dim strWorksheets(1 To 7) As String
  11.  
  12. ' Replace 3 with the number of worksheets to be imported
  13. ' from each EXCEL file (this code assumes that each worksheet
  14. ' with the same name is being imported into a separate table
  15. ' for that specific worksheet name)
  16. Dim strTables(1 To 7) As String
  17.  
  18. ' Replace generic worksheet names with the real worksheet names;
  19. ' add / delete code lines so that there is one code line for
  20. ' each worksheet that is to be imported from each workbook file
  21. strWorksheets(1) = "Audit"
  22. strWorksheets(2) = "ERROR"
  23. strWorksheets(3) = "FAILED"
  24.  
  25. ' Replace generic table names with the real table names;
  26. ' add / delete code lines so that there is one code line for
  27. ' each worksheet that is to be imported from each workbook file
  28. strTables(1) = "Audittable"
  29. strTables(2) = "ERRORtable"
  30. strTables(3) = "FAILEDtable"
  31.  
  32.  
  33. ' Change this next line to True if the first row in EXCEL worksheet
  34. ' has field names
  35. blnHasFieldNames = True
  36.  
  37. ' Replace C:\Documents\ with the real path to the folder that
  38. ' contains the EXCEL files
  39. strPath = "C:\Users\USER\Documents\Database Creations\CTR\"
  40.  
  41. ' Replace 3 with the number of worksheets to be imported
  42. ' from each EXCEL file
  43. For intWorksheets = 1 To 7
  44.  
  45.  
  46.  
  47.       strFile = Dir(strPath & "*.xlsx")
  48.       Do While Len(strFile) > 0
  49.             strPathFile = strPath & strFile
  50.                 On Error Resume Next
  51.             DoCmd.TransferSpreadsheet acImport, _
  52.                   acSpreadsheetTypeExcel12, strTables(intWorksheets), _
  53.                   strPathFile, blnHasFieldNames, _
  54.                   strWorksheets(intWorksheets) & "$"
  55.                       On Error GoTo 0
  56.             strFile = Dir()
  57.       Loop
  58.  
  59. Next intWorksheets
  60.  
  61. End Function
Jul 27 '15 #1
1 1617
Seth Schrock
2,965 Expert 2GB
You can assign the value in a textbox to a variable, which I think is what you are asking.

If code is in the form's module that contains the textbox
Expand|Select|Wrap|Line Numbers
  1. strFile = Me.Textbox_Name
If the code is in some other module or class module
Expand|Select|Wrap|Line Numbers
  1. strFile = Forms!Form_Name!Textbox_Name
Jul 27 '15 #2

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

Similar topics

5
by: hans.bonefaas | last post by:
Hi all, I hope someone can help me with the following problem in ASP.net. I want to edit the information for a record in a database (MS Access). On the page I placed several textboxes and...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
8
by: Radek Budař | last post by:
Hi all, i have trouble with changing text value of textbox on runtime. I use this control to display process information about sending e-mail per smtp. I use external component >>Imports...
3
by: Bhaskar Reddy | last post by:
Hi, I have a drop down as below. <select id="drp1"> <option value="1">One</option> <option value="2">Two</option> </select>
5
by: Aussie Rules | last post by:
Hi, Within the code of a content page, how do you say set the .text value of a label thats on the master page.... Thanks
0
by: Tuhin | last post by:
please help me wit the code of passing hyperlink1.text value with navigateurl property of the hyperlink. cannot use session variable as cannot trap the value for non availability of the onClick()...
3
nirmalsingh
by: nirmalsingh | last post by:
i have loaded a set of array values dynamically in text box from a database like this: //Response.Write("<input type=text value="+stredit+">");// then i have kept a save button:...
8
by: Raul | last post by:
Hi, I have a select list that gets populated from the DB. When the user makes a selection I am able to retrieve this value via Request.Form(...) However, I am wondering if you can retrieve...
0
by: Jabba007 | last post by:
I have an update trigger on a table called 'tbl_br' that is used to audit column changes and populate those changes into an audit table called 'tbl_audit'. See an excerpt of the code below: ...
7
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.