VB Code using variables for Forms controls
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 frmObj.name, 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 frmObj.name
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.
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".
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):
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
Combining forms with separate tab controls
I have created two forms. Each form contains a tab control. I would like to combine these two forms and incorporate information from both tab controls. What is the easiest way to complete this task? I really don't want to recreate the forms.
Can't add controls to new forms
For some reason now, when I start a new project in Visual Basic 2008, I can no longer add any new controls to the forms. All controls are grayed out in the toolbox. What can I check to see what's causing this?
Forms and controls on sub-forms
Is there any way that I can find this old, maybe 2003, message? Hans was answering a question about forms and controls on sub-forms.
It's from the Access board in Woody's Lounge.
Follow this URL to the message to look at the original post,
DeleteControl For..Each Control in Form, arbitrary behaviour
I'm trying to delete existing controls in a form before creating new ones. however, it wont delete all the controls. for every code run I create 6 controls, but for every run the "For Each" frmSub1.Controls will only delete 3.
actually, if I start out with 0 controls on my form, the first run 0 will be deleted, and 6 made. second run, 3 will be deleted, 6 made (total = 9).
third run, it will delete 5, add 6 (total = 10), same fourth run (tot=11), then stabilize on 6 deletions and 6 additions (tot=11) for every run after that. (when I want allto be deleted every time!)
why arent "For Each ctl In Forms!frmSub1.Controls" picking up all the controls?
I am trying to setup a customized Time Entry system. Anything advanced that I've figured out how to do in Access over the last 10 or so years is self taught so I wonder at times if there's an easier/better way. Like now. I'll apologize in advance if I'm confusing or not giving the right info.
I have two different time entry forms. One or the other of these forms should be visible or hidden on the main form (frmHRDB) depending on the value stored in the "TSType" field. I have code to set the 'visible' property of the two forms.
My problem is that I've attached this code to several different controls on the form so that whenever a control is clicked or whatnot the form's visible property is correct regardless of which employee is showing. But as I add more controls I'm going to have to add this code again and again. I know this can't possibly be the correct/best way to do this.
Working with the New Data Source Controls in ASP.NET (Part I)
With ASP.NET 2.0 and after, you are introduced to a bunch of new data source controls, i.e., LinqDataSource, ObjectDataSource, XmlDataSource, SqlDataSource, etc. You can use the newly added data source controls of ASP.NET 2.0 to implement CRUD (Create, Read, Update, and Delete) operations in your applications without having to write much code. All of these controls support paging, sorting, caching, editing, inserting, selecting and deleting data. You can use these controls to bind data to your ASP.NET data bound controls (GridView, Repeater, ListView, etc) declaratively, i.e., without writing even a single line of code. This article discusses these controls and how easily one can work with them.
Button Attaching Documents to Forms
I'm trying to use this API in my database to be able to attach documents to my forms.
Do I have to put this into its own Module? I'm not familiar with how the code is defining Types and declaring Global variables.
Build SQL Statements That Include Variables and Controls
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".
I imagine this is fairly straightforward but I can't find the code for it. How can I loop through all the controls in a form and amend the format, e.g. make all the controls disabled, or change the background colour of the control.
Hide Controls using VBA!
So I have several main forms which contain the same subform. This one subform contains ~4 Controls / Labels that are only necessary for one of the main forms. I'd like to hide them in all instances except when the main form is named "x".
I think hiding them is most efficient.
I've explored several variations of the below code with no effect what so ever. I've tried calling on the subform more specifically. (I.e. [Forms]![Main Form]![Subform]![Control Name].Visible = False)
Also, Should it work in this general format or do I need to specifically "call" on the Sub? For example, OnOpen, etc.