473,396 Members | 2,013 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,396 software developers and data experts.

Manually Selecting Access Table from a User Form

I create tables in the database to store project files. I've been testing a method of connecting to these tables (ex. tblTest1) from a Form using Recordset and displaying a single field in a textbox, see below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim rs As Recordset
  3.  
  4. Set rs = CurrentDb.OpenRecordset("SELECT * from tblTest1")
  5. Set Me.Recordset = rs
  6. Me.txtDiscipline.ControlSource = "Discipline"
  7.  
  8. End Sub
------------------------------
This works. However, when I try to create an InputBox to allow the user to select the specific table, It doesn't work. Sample code below. What am I doing wrong?
---------------------------

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim tblFile As String
  3. Dim rs As Recordset
  4.  
  5. tblFile = InputBox("Enter the name of the Project File ex. tbl_FileName")
  6.     If Len(tblFile) = 0 Then
  7.         MsgBox ("No Project File name was specified")
  8.       Exit Sub
  9.     End If
  10. Set rs = CurrentDb.OpenRecordset("SELECT * from tblFile")
  11. Set Me.Recordset = rs
  12. Me.txtDiscipline.ControlSource = "Discipline"
  13. End Sub
---------------------
Apr 6 '15 #1

✓ answered by nico5038

You've to substitute the tblFile with the entered value like:
Expand|Select|Wrap|Line Numbers
  1. Set rs = CurrentDb.OpenRecordset("SELECT * from " & tblFile)
  2.  

3 1199
nico5038
3,080 Expert 2GB
You've to substitute the tblFile with the entered value like:
Expand|Select|Wrap|Line Numbers
  1. Set rs = CurrentDb.OpenRecordset("SELECT * from " & tblFile)
  2.  
Apr 6 '15 #2
Nico

That was it. Thank you.
Apr 6 '15 #3
nico5038
3,080 Expert 2GB
Glad I could help.
Personally I use in cases like this a piece of code to have the user navigate to the folder and after selecting the folder I put the files of this folder in a listbox. Thus the user can only select an existing file and doesn't have to recall the name of the file.

Nic;o)
Apr 7 '15 #4

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

Similar topics

8
by: Vladimir | last post by:
Hello, I have a table in MS Access database. It has one field (with BYTE datatype) that has several properties set in Lookup tab of table Design View. Display Control = Combo Box. Row Source...
3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
9
by: Shivam | last post by:
Hi All, I have a mysql dump file... something like. __________________________________________________ CREATE TABLE nation ( ip int(11) unsigned NOT NULL default '0', country char(2) NOT...
5
by: Shani | last post by:
I need help setting up a database which includes a list of about 1200 urls. Anyone who accesses the database should be able to input wheather the url is good or bad. I want to share the databse...
4
by: yanjie.ma | last post by:
Hi, I've got a two part question on table and form design (sorry for the length but it takes a bit to explain). Our sales department uses a look-up table to help the them select the best...
1
by: Ste | last post by:
Hi, I would like to have current date automatically enter into a form that is based on a table, so that from report I can tell how many records I have entered for the day. If I use date() on...
3
by: saddist | last post by:
Hello, I have an access table with fields: ID, Name, Surname, Training. I would like to select every single row in this table to operate on it. Alghoritm would look something like that: i = 1 to...
2
by: Margie | last post by:
Hello again After getting great help perfecting my little Access 2007 movies database, I've stumbled upon an inconvenience. In my opinion it seems basic, but still I'm not able to solve it. As an...
2
by: jerrydigital | last post by:
Hi, I created a form for users to register that goes to an Access table. Unfortunately, when the user submits the form and the "Account number" text box is left empty, I get an error that tells...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
0
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...

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.