Modules & VBA :: 1 Function For Multiple Buttons / And Using Arrays For Button Colors
Mar 4, 2014
Question 1:
I am attempting to make a macro to pull information based on a clicked button to provide information to another form. While my example below will be rudimentary, I am attempting to create so that it can be applied to 450 buttons, hence the need for it to be a macro and not simply code per button.
For example if I have 3 buttons, captioned: red, green and blue. If I click on the blue button, it will open another form with a text-box that will say 'blue'. Likewise, if I click the red button the text-box will be changed to 'red'.
In the code below the section that I need to change is: Command1.Caption. Using this data I can pull from the one button to create the value, but I need it to be based on an OnClick or something in order to pull the value from the right button.
Example:
Function Macro1()
On Error GoTo Macro1_Err
DoCmd.OpenForm "Form2", acNormal, "", "", , acNormal
Forms!Form2!Text0.Text = Forms!Form1!Label0.Caption
DoCmd.GoToControl "[Text2]"
Forms!Form2!Text2.Text = Forms!Form1!Command1.Caption
[code]...
Question 2:
I am trying to use a query to change button colour on the basis of values stored in a table.What I want to do is change the button background after comparing the button name to the same variable in a table, and determining another variable.
IE:
Button1, Button2. In table: Button1, Val = Y, and Button 2, Val = Z
Pseudo Code:
Array: From Button1 to Button2
Query for Button1 against table
If Val = Y, Button1.background = red
Else if Val = Z, Button1.background = blue
Else Button1.background = black
End if
View Replies
ADVERTISEMENT
May 1, 2014
I have one color scheme I want to use all through the database I am developing. The next examples have just one color defined, to make it simpler (a dark blue, that I would call B1)
Code:
private sub setlabel()
Dim B1
B1 = RGB (0,52,105)
me.label1.forecolor = B1
end sub
... however this means I have to repeat the color definition every sub, so I thought would be neater to define a function to set my color codes (I have 20 colors).
Code:
Function SetColor()
Dim B1
B1 = RGB (0,52,105)
End function
My objective, is when I'm working in forms, Iwould (ideally) call this function "setcolor" and just write my code for the blue. I tried the examples below:
Code:
Private sub setlabel()
SetColor()
me.label1.forecolor = B1
end sub
[code]...
Again, this is probably some definition of arguments or dimensions that I am not aware oh. How to predefine the colors in a function to give them a "short" code which I can call in any sub in the database?
View 4 Replies
View Related
Jan 23, 2014
I have built an access application that contains a set of buttons along the top of every form that serve as navigation.* These buttons each perform the same function on every form they are on. (menu opens the main menu, etc) I have database macros to assign each button the same function but I still have to go through each form and manually assign them. I was wondering if it was possible to define a public function that on db open will look for all buttons with a certain name and assign them the macro. (so all buttons called cmdmainmenu will have the OpenMainMenu macro assigned and so on).Before you go there, I have already tried the navigation form and set all forms as subforms.
View 5 Replies
View Related
Jul 14, 2015
I have an endpoint for students so they can report any faults in the compound.I want to build a form that contains buttons of a certain value so that a student clicks on the button.Is fed directly to the table and pass to the next form to another value table.
View 7 Replies
View Related
Mar 11, 2014
I have built a end user form with multiple toggle buttons with "Yes/No" properties. I am wanting to link the buttons together, so if all have been selected/pressed it will read "pass" in a text box, but if even one is not selected it will read "fail". I was successful with the programming for one but not sure how to link them.
View 2 Replies
View Related
Sep 24, 2013
I try to run a function off of a button click.
The code is
Private Sub Command_Click()
Run fuctionname()
End Sub
The code is ran, but then I get a msg box : Run-time error '2517':
Microsoft Office Access can't find the procedure '.'
View 5 Replies
View Related
Jun 25, 2014
I was creating a access web app for my company and want to create a data for its product. Each product will have multiple colors and different material are used for each color. The number of colorways for a product varies.
We want to be able to select a product and a lookup field will appears for us to choose its colorway.
View 6 Replies
View Related
Sep 20, 2014
I made a database that in one of the forms, I like by clicking on a button the user be able to select 5 excel files with different file names (in the same directory) and then based on the imported file's names, it be stored in 5 different tables.
At the moment by using the bellow code, I can import multiple files (with the same formats) only into one table . My vba code comes as follow:
Function GetAllFiles()
Dim fd As Object
Dim strFilter As String
Dim lngItems As Long
Const msoFileDialogOpen As Long = 3
Const msoFileDialogViewDetails As Long = 2
[Code] ....
View 4 Replies
View Related
Dec 8, 2014
I have a table EmployeeInfo containing three fields
EmployeeId
Name
FatherName
I have created form for this table.
I do not want to use autonumber for employeeid for some reasons. I want to place a button along employeeid test box on form.
User will click on the button it will get max employee id from employeeinfo table and add 1 and copy it into employee id text box.
What will be the code for button click event.
View 2 Replies
View Related
Nov 12, 2013
I have a command button that basically saves the record that i just finished entering. here's the code:
Private Sub cmdAddAnother_Click()
On Error GoTo Err_cmdAddAnother_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_cmdAddAnother_Click:
[Code] ....
What I'd like to do now is add a second function that will make all the controls on the form go to null after the record is saved. so the user can start from scratch and add another record.
I tried adding me.refresh right before "end sub" but that didnt work.
I tried adding "me.controlname.value = null" for every control on the form, and that didnt work either.
I also tried adding this code that i found on bytes.com:
On Error Resume Next
Dim ctl As Control
For Each ctl In Me.Controls
ctl.Value = Null
Next
That didn't work either.
View 4 Replies
View Related
Jun 25, 2013
I'm still learning Access 2010 and having issues getting my buttons to work. I'm working on a simple address database.edit/save button. On form load, my fields are locked and my button will read "edit". After clicking, my fields are unlocked, my search features are locked, and my button reads "save" just how I need it to. The issue happens when I try and save the field edits, lock fields, return search features, and get button to read "edit" again. I know I need to add some code into what I already have, but I'm running into a wall as I have tried many options to get it to work. Here is the code for this button:
Code:
Private Function Lockdown() 'locks controls at load
Dim tb As Control
Dim cb As Control
Dim subf As Control
[code]...
Second issue is with my report button. I have not been able to get this to work once. I have done many searches on single record reports, and have found the same code every time. I added that code into my database, but can't seem to get it to work. In my database there are two address (shipping and work location) which I would like to print out together. I have the work location on the main form and the shipping on a subform. There are and upwards of 150 locations I will have in my database, Here is the code I'm working with:
Code:
Private Sub cmdrptadd_Click()
Dim strReportName As String
Dim strCriteria As String
[code]...
View 3 Replies
View Related
Jul 24, 2015
I have a database with various tables containing information about students, timetabling, assignment submission dates and multiple tables with grades for various assessments. All grades are held as percentages.
In a large number of different queries / reports I want to output the grade as an item from verbose scale with 17 points (excellent first, high first etc.). I've set up a table called 17pointscale which contains fields called 17pointscale (with the verbose names), lowerlimit (number) and upperlimit (number).
I have a query in SQL (which works) to take the percentage grade from one of my grade tables AssessedWorkGrades.Grade and return the text on the 17 point scale.
SELECT AssessedWorkGrades.Grade, [17PointScale].[17PointScale]
FROM AssessedWorkGrades LEFT JOIN 17PointScale ON ([AssessedWorkGrades].[Grade]
>= [17PointScale].[LowerLimit]) AND ([AssessedWorkGrades].[Grade] <= [17PointScale].[UpperLimit]);
Is there any way of converting the SQL to a custom vba function which would enable me to use this as a lookup in a large number of queries.
I think that it should be possible to set up a function called ScaleGrade and in any query Expression: ScaleGrade(XXX) will take XXX and return the 17 point scale.
I think that AssessedWorkGrades.Grade needs to be replaced by a variable that is inputted on use of the function but am not sure how to accomplish this.
View 1 Replies
View Related
Jan 11, 2014
Trying to run a query where each 4 fields calling a custom function will not just re-run the same custom function over and over again for each field in a single record.
A Function has a huge amount of multiple queries and logic to perform.The Function returns a Integer, Integer, Integer, and optional Integer. Each integer requires a DLookup to lookup a String description value for each individual integer (in each of 4 fields).
The problem is, the DLookup in each column that runs against each of the integers re-run the same function.The result is that a single record, each of the 4 columns returning a single of the 4 values, the complex function is re-run 4 times.
The function is huge, part of a Business Rules Engine. Depending on the Rule-Meta data - it might launch up to a dozen queries and perform logic steps for each record. This is not the ordinary SQL Query.
Imagine if one record (for 1 field) takes 0.1 second to run. By referencing the function in 4 columns, this same function is re-run 4 times (0.4 Seconds) Against 50,000 records - this duplication of re-running the function for each column can really add up.
Possible Solutions: Researched Class Modules - There is a comment that the property Get, Let actually reduce performance. There are huge advantage of code documentation, documentation and centralization.It doesn't claim class modules reduce execution as each propery is returned. It also describes that Class Modules can't be called directly in a Query - unless each property is wrapped in a function.
Function Returns one String with delimiters: e.g 34;54;55;1 This single column goes into a Make Table (runs function one time per record) Then the D-Lookup is run against static local data. This pevented the function from being run over and over across the network linked data.
Final Solution: Eventually, the many hundred lines of VBA code for the Rules Engine will be converted into SQL Server T-SQL Functions on the server.For a Rule Engine development, Access has been great for a rapid protoype development and testing. The TSQL will be a final big step requiring re-coding. It is not currenty my option for the delivery time frame.
View 8 Replies
View Related
Jun 11, 2013
I have multiple reports that use similar IIF statements as the controlsource for four textboxes. Naturally, I don't want to have to update twelve controlsources if any of the calculations change, so I thought I'd make this a public function. However, I don't know how to pass along multiple textboxes as variables. Here's what I have so far:
Code:
Option Compare Database
Public Function txtColor(ByRef textbox As Control)
Dim str1, str2, str3, str4 As String
'The IIf statement is simplified for this example. It's not important.
str1 = "=IIf(IsNull([Inquiry start date]),'W',IIf([txtInquiry]<1 And IsNull([Inquiry end date]),'R'))"
[Code] ....
And this is in the report (where ??? is what I'm asking about)
Code:
Private Sub Report_Load()
Call txtColor(???)
End Sub
The error I get is "Runtime 424 Object Required"
View 7 Replies
View Related
Jul 23, 2013
Access 2007: I have a continuous form which, when it opens, uses code to display alternating colors... I need to set a default 'alternate' colour, and I want to find the code to use for Light Grey - on the design of a form, the color to use on a control would be #903C39 but when I try to set that as my default colour in the code it doesn't like it! I can use vbRed, vbBlue, vbYellow, etc, and that works perfectly but I can't find a vbLightGrey
View 6 Replies
View Related
Jul 25, 2013
I want to run multiple SQL commands on click of a button. I have these three command,
CurrentDb.Execute "INSERT INTO UserMadeDeviceT(Product, ORESector) " & _
" VALUES ('" & Me.D_NewDeviceTxt & "', '" & Me.D_ORECmb & "')"
CurrentDb.Execute "INSERT INTO UserMadeDeviceT (RatedKilowattPower, KilogramWeight)" & _
" SELECT RatedKilowattPower, Weight FROM UserSelectedComponentT " & _
" WHERE [TotalComponent] = '" & D_ComponentNameCmb & "'"
CurrentDb.Execute "INSERT INTO UserMadeDeviceT (Cost) SELECT SUM (EuroCost) FROM UserSelectedComponentT"
all of these work indevidually and return the correct value but the add three rows to the table. How can I combine these three commands into one so that it will only add one entry?
View 8 Replies
View Related
Feb 1, 2014
I have a contineous form with a combobox for each record and i have a button to select the first item in the combobox then to refresh the list in the combobox .I want to creat a one button to select the first item in the combobox then refresh the list then go to the next record and select the first item on the list
View 2 Replies
View Related
Jul 22, 2015
I am looking for a way to enable a user to fill in a number of fields on a form press a button(CreateButton) and duplicate the records how ever many times is stated in a text box(TxtQty). I also need this to increase the serial number by the amount of times stated in the text box.
There will need to be another text box (TxtNextSerialNumber) stating the next first available serial number
For Example:
TxtNextSerialNumber = AD-Oracle-00010
TxtQty = 5
Press CreateButton to create 5 records
TxtNextSerialNumber = AD-Oracle-00014
5 new records created with the below fields duplicated and the above happening.
I will then need a message box informing the user of the serial numbers created:
'You have created serial numbers AD-Oracle-00010 to AD-Oracle-00014'
Table Name: ADOracle
Form Name: ADOracleTestData
Fields Names:
CustomerName: Duplicate
PartNumber: Duplicate
OrderNumber: Duplicate
OrderDate: Duplicate
HoseKit: Duplicate
Returns: Duplicate
Comments: Duplicate
SerialNumber: + the amount shown in TxtQty starting on next serial number available.
View 6 Replies
View Related
Jul 23, 2015
Is there any way to press a command button a certain amount of times based on a value in a text box.
i.e.
text box value = 5
button gets pressed 5 times with one click...
View 14 Replies
View Related
Jul 31, 2014
I work for a company that manufactures home appliances & electronics. When those products fail within the warranty period, we are obligated to repair the units for the customers.
We have around 200 factory technicians who make those repairs. Each tech is able to make approximately 8 repairs each day. We have a dispatching system that assigns the repairs to the techs based on their availability each day. But the problem is that we have to manually enter and adjust the schedule for all 200 techs every single day, and this takes a lot of time. And of course technicians get sick, take vacation, etc, so we have to adjust the schedule so no techs will be assigned calls when they're off.
The problem: For example, currently when a technician takes off for 2 weeks, the user has to enter 14 individual records for the tech, which is somewhat time consuming. What I need is to program a button click event to determine the two dates (startDate & endDate) and append multiple records from one single entry in the form for each date in between and including the two date fields.
I know I'll probably need to create a loop that will loop through the two dates on the form and append a record for each day, so I can then cross reference the dates to the master schedule dates to make sure that no availability is opened for the techs taking time off.
View 3 Replies
View Related
May 30, 2005
Hello everybody,
I’m new here and I have a question for you..
Is it possible to place round buttons or oval buttons on your forms instead of the normal square ones?
Greets,
Tom
View 2 Replies
View Related
Jun 25, 2007
Hi all
I need some help with an array.
I have 10 fields each with 5 possible values. At the moment I've written 50 if then statements.
is there a cleaner way to do this?? I thought perhaps an array of some sort may do the trick.
Any advice is appreciated
Damon
soc5 = DLookup("[effort]", "values_effort", "ID=5")
soc4 = DLookup("[effort]", "values_effort", "ID=4")
soc3 = DLookup("[effort]", "values_effort", "ID=3")
soc2 = DLookup("[effort]", "values_effort", "ID=2")
soc1 = DLookup("[effort]", "values_effort", "ID=1")
soc0 = DLookup("[effort]", "values_effort", "ID=0")
's1
If Me.txtFieldS1 = 5 Then Me.txtS1 = soc5
If Me.txtFieldS1 = 4 Then Me.txtS1 = soc4
If Me.txtFieldS1 = 3 Then Me.txtS1 = soc3
If Me.txtFieldS1 = 2 Then Me.txtS1 = soc2
If Me.txtFieldS1 = 1 Then Me.txtS1 = soc1
If Me.txtFieldS1 = 0 Then Me.txtS1 = soc0
's2
's3
's4
..
...
...
View 2 Replies
View Related
Jun 23, 2005
I am not even totally sure that is what you call it. . but I have most of my experience in VB.NET and this VBA in Access 2002 is killin me. HA. . .
I am trying to dynamically create checkboxes (50 of them) in 10 rows and 5 columns. This is part of a "im bored" project and would like to be able to tackle the dynamic controls area.
I am thinking I want to keep the naming convention as "chkBox01. . .02. . .03" so that I can use the mid() function to determine its "value" and apply the value in the proper place.
I suppose the only thing I need is an example if anyone has one of a checkbox or any control for that matter being made by VBA and not placed on the form manually. 50 check boxes suck when trying to rename them all. sigh
View 11 Replies
View Related
Jan 24, 2008
Hi,
How can I determine the length (size) of a dynamic array so I can iterate over it?
Thanks,
Mike
View 2 Replies
View Related
Jun 25, 2006
Was woundering if the was a way to habdle multiple command buttons with one procedure. I have done a little VB.Net and I remember that you coud use one sub to handle multiple buttons using the handles key word. I was wondering if Access could do that. What I have is 37 command buttons named cmdView1 through cmdView37 all I really need is the number that prefixes the command buttons name. I know how to pull out the number but I can not figure out how to use only one sub procedure for all 37 buttons. Any help is appreciated.
Frank
View 2 Replies
View Related
Dec 11, 2013
So basically I need making a function that will count the number of records from another table/query based on a field from the current query.
View 2 Replies
View Related