473,386 Members | 1,830 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,386 software developers and data experts.

Setting the ControlSource of a form from a variable in VB

My programming grammar might be a little off but I have a pretty good
idea of what I need to convey.

I am making an Access database with a form that pops up and lets you
choose to select an existing exercise or a new one. I want to focus on
the new exercise selection for now.

When selecting the new exercise a textbox appears where you enter the
new exercise name. This is passed and used to create a table and a
form from a template table and form. What I need to do is change the
control source of the new form when it is created to the new table.
Below is what I have:

Public Sub Form_Load
Dim ExerciseName As String
Dim NewExerciseName As String
Dim ExerciseTable As String
Dim ExerciseForm As String
End Sub

Private Sub btnEnter_Click()
If txtNewExercise.Visible = True Then
NewExerciseName = txtNewExercise.Text

DoCmd.CopyObject "", "tbl" & NewExerciseName, acTable,
"tblTemplate"

Dim db As DAO.Database
Dim rs As DAO.Recordset

**Below creates an entry into a table for later use**
Set db = CurrentDb
Set rs = db.OpenRecordset("tblExercises")
rs.AddNew
rs.Fields("Exercise_Name") = Me.txtNewExercise
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing

....

DoCmd.CopyObject "", "frm" & NewExerciseName, acForm,
"frmEntryTemplate"
ExerciseTable = "tbl" & NewExerciseName
ExerciseForm = "frm" & NewExerciseName
DoCmd.OpenForm ExerciseForm, acNormal, "", "", acAdd,
acNormal

**From here I am lost, what I would like to do is make
ExerciseTable the ControlSource for ExerciseForm, but I am having
trouble using the variable names to set the ControlSource.**

Jul 25 '06 #1
1 3471

"Mexar" <me***@cox.netwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
My programming grammar might be a little off but I have a pretty good
idea of what I need to convey.

I am making an Access database with a form that pops up and lets you
choose to select an existing exercise or a new one. I want to focus on
the new exercise selection for now.

When selecting the new exercise a textbox appears where you enter the
new exercise name. This is passed and used to create a table and a
form from a template table and form. What I need to do is change the
control source of the new form when it is created to the new table.
Below is what I have:

Public Sub Form_Load
Dim ExerciseName As String
Dim NewExerciseName As String
Dim ExerciseTable As String
Dim ExerciseForm As String
End Sub

Private Sub btnEnter_Click()
If txtNewExercise.Visible = True Then
NewExerciseName = txtNewExercise.Text

DoCmd.CopyObject "", "tbl" & NewExerciseName, acTable,
"tblTemplate"

Dim db As DAO.Database
Dim rs As DAO.Recordset

**Below creates an entry into a table for later use**
Set db = CurrentDb
Set rs = db.OpenRecordset("tblExercises")
rs.AddNew
rs.Fields("Exercise_Name") = Me.txtNewExercise
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing

....

DoCmd.CopyObject "", "frm" & NewExerciseName, acForm,
"frmEntryTemplate"
ExerciseTable = "tbl" & NewExerciseName
ExerciseForm = "frm" & NewExerciseName
DoCmd.OpenForm ExerciseForm, acNormal, "", "", acAdd,
acNormal

**From here I am lost, what I would like to do is make
ExerciseTable the ControlSource for ExerciseForm, but I am having
trouble using the variable names to set the ControlSource.**
I would think you would need to open the form in edit mode not acNormal.

But why would you create a new table and report for each exercise? You added
the new exercise to the tblExercises table. Open the standard form filtered
to the new exercise.
Jul 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: TF | last post by:
hi, i am using a ListBox control on a windows form using VB.Net. when i set the DataSource property of the control to an ArrayList it fires following events in this order: SelectedIndexChanged...
3
by: Shelli Carol | last post by:
Good day, I have: 1) A table with numbered fields (1, 2, 3, etc.) 2) A form text box, whose ControlSource property contains an expression. This expression returns a number. If I just...
4
by: Steve Jorgensen | last post by:
Hi all, This is actually not an issue of mine, but one a friend of mine told me about that I was able to confirm. Let's say you want a highly customizable report, so you want to be able to do...
3
by: Otie | last post by:
Is there a simple answer as to why my database will not save the data that correctly appears in the AccountID textbox on a form to the table when I set the AccountID.ControlSource =...
6
by: MLH | last post by:
I have a form named frmVehicleEntryForm. It has a 3-tab tab control. On the 2nd tab page, there's a textbox named VehicleLocationName whose default value setting is ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Michael R | last post by:
Hello. I need a help to solve the following: I'm intersted in having the Control Source of a textbox as following: ="Comment, " & When I input this from Design View into the Control...
13
by: ringer | last post by:
Hi, I have a text box on report where I need to have dsum return a total. The records I need the total from are not in the table that is the report's recordsource, and to complicate things...
14
by: OldBirdman | last post by:
I have a textbox on a continuous form that I want to display a calculated value. I have set the ControlSource Property = & "~" & . I would like to have my user be able to correct this value, and...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.