473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use a text value as a variable in VBA

1 New Member
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 1626
Seth Schrock
2,965 Recognized Expert Specialist
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
2352
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
5680
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
2838
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
21846
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
1797
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
1211
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
3560
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
3882
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
1084
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
3563
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
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6719
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2980
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.