Topics Search

VB Code using variables for Forms controls

VB Code using variables for Forms controls
Views: 11
Like to put the form property name in a variable. I have a table that controls form element. Hols formname, fieldname, Propertyname and the Value I want the property set to.

Formnname = "test_form"
FieldName = "command0"
Propertyname = "Visible"
Forms(Formname).Form(FieldName).Propertyname = False

Can not seem to figure out if you can put the property name as a variable like the form name and fieldname.
Sponsored Links:

More topics


How to pick the maximum value from variables in code

I have four variables DHVN, DHVE, DHVS, and DHVW that are calculated in my code. Next, I need to do another calculation that involves picking the highest of these four variables. Can someone tell me how to do this

How to: Build SQL Statements That Include Variables and Controls

Describes how to to construct an SQL statement that includes variables and control values in code.
When working with Data Access Objects (DAO) or ActiveX Data Objects (ADO), you may need to construct an SQL statement in code. This is sometimes referred to as taking your SQL code "inline."

variable handling with multiple users

I have an Access 2007 database which is located on a shared disk. De the database is an ACCDE in running environment (renamed to accdr).
I created some Module classes and many functions which are used by the forms in the database. The user will be able to make some selections in listboxes, checkboxes and other controls and then generate an Excel file with the filtered data.

My question is whether the values of the global variables and classes used by the form will be affected when a second, third or nth user opens the database at the same time and makes his own selections. So in short: will Access create a new set of global variables for each user and make those variables only accessible within the session of that user?

I might be able to test this in a week, but I need to advance with my coding now. Any insight regarding forms with multiple sessions is

how do I open all forms, and going through all controls?

What I want is to open all forms, one by one, and going through all controls to edit The .OnMouseMove event
How can it be done ?

I tried to use this piece of code:

Dim frmObj As AccessObject Dim ctl as Control
For Each frmObj In Application.CurrentProject.AllForms
DoCmd.OpenForm, acDesign

This work but I can't find the way to go through controls as what I get is AccessObject and not a Form object, and can't use this part of the code:

For Each ctl In

Paint command button in activeX controls or Forms controls

1. Can I somehow paint command button in activeX controls or Forms controls, and if I can how?

2. Can I hide active controls command button depending on forms control check box. (If its turn on I can see buttons, else I can't.) and if I can how?

The Windows Controls of a Form

A typical database is made of forms (and reports) and these objects are equipped with Windows controls that allow a user to interact with the computer. To create such a database, you add forms and reports to it. Then you populate them with the necessary objects. This is the essence of application design and you should know how to design the controls.
Form and report design consists of populating them with the necessary controls that would allow a person to use your database. To perform this design, you first open the form or report in Design View.
Topics: Control Design, Common Properties of Controls, Tables Columns and Windows Controls, Common Methods of Windows Controls, Common Events of Windows Controls, Windows Controls: The Label, Windows Controls: The Group Box, Windows Controls: The Text Box, Windows Controls: The Month Calendar, Windows Controls: The Date Picker, Windows Controls: The Time Picker, Windows Controls: The Command Button, Combo and List Boxes, Check Boxes and Toggle Buttons.

Background color of forms controls

From a database I have inherited, I have noticed that any forms background colours are white until the cursor is put into the control when the background changes to yellow? This doesn't happen for all controls though just the majority. There is no code to change this background colour or at least I cannot see it.

only checks first record

the message box only displays if the first record in the subfrom "00upc created" contains the value 3. I would like the code to check all records in subform.

Private Sub Command220_Click()
On Error GoTo Err_Command220_Click
If Me.Form("00 upc creatED").Controls("group 2").Value = 3 Then

MsgBox ("Already created! Try Again.")


DoCmd.OpenForm "00 upc create", , , ""
Forms("00 upc create").Controls("dvd release").Value = Me.[DVDID]
Forms("00 upc create").Controls("group 1").Value = 1
Forms("00 upc create").Controls("GROUP 2").Value = 3
Forms("00 upc create").Controls("PRICE").Value = Me.Text229

End If

Exit Sub

Resume Exit_Command220_Click

Adding controls to a form fails because they disappear.

I have an add-in that creates a form, adds controls to it, then tries to add some more. But on the second attempt to add controls, they disappear. If I have an error in my code that gets displayed in a message box I can see the new controls behind it.

When I click OK they disappear. they are there according to properties, although I can't see them because the form will not display while in debug mode.

When the program finishes, the controls that were created are gone. Too bad there isn't any documentation (or any than can be found) that describes how to do this.

Here is the code to create a form and controls (it works):


Then I try to add controls to the form with this (they disappear):

Loop Though Controls on Form and Work with Them

How do I achieve it? I have a series of fields (either text box for entry or label for displaying calculated results) that constitute a "Table" on an Access 2007 form.

When one of the fields changes (obviously, a text field), I need to recalculate the various values and paste them into appropriate labels in the same "Row".

Currently, I've duplicate the code for each controls "After Update" and changed the control names accordingly (sample below)


As you'd be aware, this a MAJOR pain the rear to maintain as I need to make any changes at least 13 times across the various routines.

What I'd like to be able to do is create a Function where I can pass in the names of the relevant controls and maintain one code block instead of 39+ duplicate blocks.


This little code block (I was hoping) would locate the various controls on the form and assign them to the control variables so I can use them in place of hard-coded control names in the first code snippet.

What I'm getting is an "Run-time Error '91' - Object variable or With block variable not set".