I have a user form that posts scores to a person's file. The way it works is the person starts by entering their name and then answers a series of 13 questions. The UserForm is attached to TestingFile1 and once they are finished they click a button and it "posts" the results to their file Example X:rep testing\2018 reps\SchJ.xlms (The test file is located in a different directory) the cell I would like to link to takes all the results and shows an average. The data goes to the rep but the form goes to the rep's supervisor. I would like to add a box on the testing form that once the rep enters their name, based on the name it would show their current average in the form (this would be before the current test. That current cell in the Reps file that holds the running average is o26.
Having never tried this before this is what I currently have but it's not going to work.
Private Sub TextBox1_Change()
If CSRep.Text = "Alyssa Vangundy" Then
Textbox1.Text = X:\Audit Tracking\Reps\2018 Reps\[VanA.xlsx]VanA'!O26
End Sub
Related
I have a table called GL_Account and IM_Productline
The table IM_Productline has various fields that need to be populated with a value from the field GL_Account.AccountKey (i.e. IM_ProductLine.InventoryAcctkey and IM_ProductLine.CostOfGoodsSoldAcctKey)
To populate the IM_ProductLine table I made a form "Product Line Maintenance" with all the fields. To populate the field IM_ProductLine.InventoryAcctkey I put a (magnifying glass) button behind the field with the following code:
Private Sub CMD_Select_GL_Account_Click()
Me.Refresh
If IsNull(Select_ProductType) Then
'do nothing
Else
Forms![Product Line Maintenance].InventoryAcctkey = Me.SelectGLAccountKey.Column(0)
Forms![Product Line Maintenance].Refresh
End If
DoCmd.Close
End Sub
So the button opens a form Called "Select GL Account" with a combo box that enable to SELECT GL_Account.AccountKey, GL_Account.Account, GL_Account.AccountDesc
FROM GL_Account; and when the OK button is clicked it writes the value from GL_Account.AccountKey to IM_ProductLine.InventoryAcctkey, closes the form "Select GL Account" and then refreshes the form "Product Line Maintenance" so the account number and description become visible for the user.
This all work fine but here's my question:
Now rather than creating a new form for every account field I need to populate (i.e. "Select Inventory GL Account" select "Cost Of Goods Sold GL Account" etc) I'd prefer to use the form "Select GL Account" to select and populate the 11 different account fields. So behind each xxxAcctkeyfield on form "Product Line Maintenance" is a (magnifying glass) button that when clicked pulls up the form "Select GL Account" and when "OK" is clicked it writes the selected AccountKey to the correct field on form "Product Line Maintenance"?
I'd greatly appreciate anyone's efforts to understand what I am trying to explain and point me in the right direction.
Ok, there is the issue that all 11 fields should not require to be "copied" since you have a relational database (you would ONLY store the row PK ID of that selection in the current report. (a so called FK (foreign key) value). That way, say you want to change the choice? Well then you could pop up that form - search + select the one record with all that information, and then upon return ONLY store the one value.
So, I would give some thoughts to the above - you want to leverage the relational database features. And as a result, you don't need to "copy" all that data. This is not much different then say creating a invoice. I can create the new invoice, but all of the address information, and the customer that this ONE invoice belongs to? Well, that is one column with a FK value that points to the customer. Once I select that one customer, then display of the customer name + address can be say a sub form or some such - but no need exists to "copy" that information. It would also means with near zero code, you could move a invoice between customers!!! - (just change the one fk column with to the new/different customer ID (PK) value.
Now, back to the question at a hand?
You can certainly pop up a form, let the user select, enter, pick and do whatever. And THEN you can have the calling code grab + pick out the values from that form.
The way you do this? It involves a not too wide known trick.
The code that calls the form can simply open that form as a dialog form. This will HALT the calling code, the user does whatever, and when done the calling code will THEN continue. Not only does the calling code continue, but it can get/grab/pull/take any values from that pop up form WIHOUT having to use global vars.
The approach is thus thus:
dim strF as string
strF = "frmPopAskInfo"
docmd.OpenForm strF,,,,,,acDialog
' above code waits for user input
if application.AllForms(strF).IsLoaded = true then
' user did not cancel, get values from form
me!AccountNo = forms(strf)!AccountNumber
etc. etc. etc.
docmd.Close acForm,strF
end if
Now the only other issue? Well, the "ok" button on the popup for DOES NOT close the form, what it does is set visible = False. This will kick the form out of dialog mode.
me.Visible = False
So, if the user hits the cancel buttton (close form) or hits the X upprer right (close form), then the form will NOT be loaded when your calling code continues. But, if they hit OK button, then you don't close the form, but ONLY set visbile = false.
This allows the calling code to continue, you are free to get/grab/take values from that form, and then once done, you close the form.
So a form close in that popup = user canceled the form.
So, a popup form, and even a modal form? They do NOT halt the VBA calling code, but a acDialog form does!
You can thus place 2 or 5 little buttons that pops up this form, the user can pick/choose/select/enter values. When they hit ok, your calling code continues, and you are free to pull values from that form. So while all 3-4 buttons might pop up that form, each individual button launch of the form can have code that follows and updates the given control the pop button was placed beside.
I am building a simple program around an Access database using VB.net, and I'm having an issue.
As shown in the screen capture provided, I have a Next Record and Previous record button to navigate the database's information on this particular tab control. The Next Record button works fine (though I would like to make it loop back to the start once Next Record is clicked on the last record), but the Previous Record button erases both name labels while still displaying the band name, country, instrument, and ID number. The code for the Previous Record button is:
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
Me.MusiciansBindingSource.MovePrevious()
End Sub
I have tried repopulating the data with Me.MusiciansTableAdapter.Fill(Me.MusiciansDataSet.Musicians) before the record moves back, but that didn't work. I'm at a loss for what else to try. Here is the aforementioned screen capture.
I can provide more information if needed. Thanks in advance!
I got a Database, where I apply to a name a Main and Subgroup.
When I enter a MainGroup f.e. Granades, just subgroup elements like "attack-granades" etc. should be shown.
In genereal it works by writing in this into the MainGroup-Combobox at my Form.
Private Sub MunHauptgruppeRef_AfterUpdate()
Me.MunUntergruppeRef.Requery
Me.MunUntergruppeRef.RowSource = " SELECT UnterGrpNR, UnterGrpName FROM tbl_UnterGruppen WHERE UnterHauptGruppenNr = " & MunHauptgruppeRef.Value & " ORDER BY UnterGrpName ASC"
The Problem is, if I load the datas in my form again, it just shows the related Number to the "Sub-Combobox data" 1( f.e. 35 for Attack-Grenade ) , but not the Name itself. After I reselect the entry in my Main-Combobox(Grenade), it shows the right sub-data which was saved. 2
Tried Requery on Form_Load or Requery of the Combo-Boxes itself. nothing helped so far.
Made some Video3
You need to add the code from Private Sub MunHauptgruppeRef_AfterUpdate() to your Form_Current event, this will refresh your combo box row source to the current value of your MunHauptgruppeRef combobox as you cycle through your records. Also you need to call the Me.MunUntergruppeRef.Requery after you've set the Me.MunUntergruppeRef.RowSource.
You can also add a check when your in a New Record, for the code not to run on the Current Event. See here https://learn.microsoft.com/en-us/office/vba/api/access.form.newrecord
I'm working on a project for my Visual Basic class in which I'm supposed to read in a file and display the information (employee names and salaries) in a list box.
I have a total of 4 forms.
The first form doesn't actually display anything, it simply has the menu items to open the file, select any of the other 3 forms, and exit the form.
In the second form (names), only the employee names read in from the file are displayed in the list box.
In the third form (salaries), only the employee salaries read in from the file are displayed in the list box.
The fourth form is basically just like the second and displays the employee names read in from the file.
The problem is, I don't know how to do this so that only certain parts of the file are displayed in the list boxes (names and salaries). Also, in the fourth form I have to ask the user to enter the amount of months that they would like to calculate the salary for the selected employee and then multiply their salary by the number of months entered by the user. I know how to do this, except for how I would go about getting the salary. For example, I'm thinking it would be something like this:
lblTotal.Text = dblSalary * intMonths
But I don't know how to store just the salary of the selected employee in the dblSalary variable?
Here's what code I have written so far, however it's simply opening an open file dialog box when the user clicks File->Open from the main form
Public Class Main
Private Sub OpenFileToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenFileToolStripMenuItem.Click
Dim open As New OpenFileDialog
open.Filter = "text files |*.txt|All Files|*.*"
open.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
End Sub
End Class
And here is my text file titled employees.txt
Steve McGarret
1500.00
Danny Williams
1300.00
Matthew Casey
1700.00
Kelly Severide
1750.00
I hope that's clear, if not let me know and I can try to clarify.
Thanks in advance.
Since this is homework, I won't post a specific solution, but I'll post the idea of how I would do it...
I would:
Create 2 new List variables - Dim Names as new List(Of String) & Dim Salaries as new List(Of Double)
Read the text file line by line and, given the file format, each even line will add to the Salaries list and every odd line will add to the Names list
Set each list as the DataSource for the appropriate listbox
Hope this helps and gives you an idea of how to proceed, at the very least.
UPDATE:
Given your comment saying you wanted to store the data in a class, you could do something more along the following:
Create your Class with the 2 attributes and whatever other methods you need - Call it EmployeeData, say
Create a List Of(EmployeeData)
Loop through the text file 2 lines at a time (meaning read in the first line, capture the name, read in the next line, read in the salary, THEN loop)
In each loop, once you've captured the data, add a new EmployeeData to your list with the 2 pieces of captured information.
Write a small bit of code that will extract from your EmployeeData list only the salaries or only the names as a new list that you can use to bind to your listbox as the datasource.
Hope this makes sense.
With almost 0 knowledge in VBA I have created a Data Form to enter daily voucher with:
MS Date and Time Picker
TextBox1 for Amount (validated for numeric value only - working fine)
OptionButton1 for Cash
OptionButton2 for Cheque
TextBox2 for the name of person Paid To (maybe I can change it into a ComboBox?)
TextBox3 for Paid For (any value can be entered)
ComboBox1 for Sub Category (list is in Worksheet2 (List) - working fine)
TextBox4 for Remarks (any value can be entered)
CommandButton1 to add the data into Worksheet3(database)
CommandButton2 to show the 'database' worksheet
CommandButton3 to close the form (working fine)
A CommandButton is also in Sheet1(Form) to open the form (working fine).
I want to enter the data into the form and populate this data to Worksheet3(database) as
Date in (B3), Paid To (C4), Paid For (D4), Sub Category (E4), Remarks (G4), Amount (H4).
(F4) is free for a VLOOKUP.
I also want to have a data edit option in the form that may be with an auto-generate voucher number with recall option.
Can any one help me with the appropriate code to do this?
Note: I am creating with Office 2007 but also want to use it in XP Professional
On the first part of your question, it depends whether you want to populate worksheet3 on the click of a button or dynamically as the data is entered into the form. I'm assuming the former as most forms have OK buttons on them. If this is the case then you can write a subroutine based on the button click, to give a simple example:
Private Sub Enter_Details_OK_Click()
Sheets("worksheet3").Range("B3").Value = Calendar1.Value
'Change Calendar1 to the value of your date/time object and change "worksheet3" to the actual name of your worksheet.
Sheets("worksheet3").Range("C4").Value = TextBox2.Value
'...and so on...
You are basically transferring the values from each text box into various cells. I'm not sure what you mean on the second part of your question, that needs further clarification.
Hope this makes sense!