I have a combo box which is linked with a table (products) and i need to fill fields automatically when the user select a value.
Datas in the fields are also from the table products.
Thanks
If your combobox row source is
SELECT ProdID, ProdName, ProdColor FROM Products
and column widths 0;3;0 (i.e. only ProdName is visible), you can use the AfterUpdate event to copy data from the combobox columns to other controls.
Private Sub cboProduct_AfterUpdate()
Me!txtID = Me!cboProduct.Column(0)
Me!txtColor = Me!cboProduct.Column(2)
End Sub
Easiest way will be just to create yourself a myComboBox_SelectionChanged() event. Then within your method assign the values where you want them.
Private Sub myComboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles myComboBox.SelectionChanged
// Exact the selection here and put it in your table.
End Sub
Related
thanks in advance for your help.
I have a form with spreadsheet view that has 3 fields I want to use to sort: Customer, amount and currency.
When I do the sorting by hand, I sort the amount ascending, the currency A-Z and the customer A-Z following that specific order (the result of sorting fields one by one is a table structure I like because it is easy to read). I do this by clicking the field's header and activating the sort, one field at a time.
I tried to replicate this sequence by adding a macro to the form that runs when the form loads, however it seems like the sort is manipulating the 3 fields at the same time. The result does not look like the one I get when I manually sort one field at a time.
Private Sub Form_Load()
Me.OrderBy = ""
DoCmd.SetOrderBy "Amount DESC, Currency ASC, Customer ASC"
End Sub
Is there any way to set fields sorts one after the other?
Thanks.
Try this:
Private Sub Form_Load()
Me.OrderBy = "Amount DESC, Currency ASC, Customer ASC"
Me.OrderByOn = True
End Sub
NET (basic) I have on form1 a DGV1 displaying customer names (Dataset from SQL Database). I want to double-click on "a" customer name in DGV1, form1 and then see "Customer Details" in DGV2, form2.
I can make that on one form, easy DGV1 and DGV2 when select customer name in top DGV then bottom DGV updates accordingly. I want this on two forms as above explain.
Thanks,
Michelle
Try this one I think this the one that your looking for,
'This code below will hold the Value from your table
Dim CustomerName as String
'This code below will hold the value of the selected row in DGV1
Dim SelectedName As Integer
SelectedName = DataGridView1.CurrentRow.Index
Now here is what you do lets say the customers name is in Column1 now we will get that value like this.
CustomerName = DataGridView.Item(1, i).Value
So what happens everytime you select a data in column1 the value of that selected row goes to the CustomerName.
What is next you will do is create a Form2 add the Datagridview and in your code run this one.
Form2.Show
'Create your own way of display data in datagridview but this time your where clause is like this (where ColumName = '" & CustomerName & "')
Regards
I have a gridview which currently pulls in all records from a table. Additionally i have 4 dropdownlists that are databound to all possible values for each of the 4 columns and the dropdownlists lists are set as controls in the gridview for the database query.
On each downdownlist i have appended a blank value to the top which is the default value and anytime this value is chosen, the database uses this to return all results (no filter on that column when null).
This is the current database query.
SELECT
Week_Ending, Employee, Project, Status_Of_Employment
FROM
Times
WHERE
(#Project IS NULL OR Project LIKE #Project)
AND (#Employee IS NULL OR Employee LIKE #Employee)
AND (#Status_Of_Employment IS NULL OR Status_Of_Employment LIKE #Status_Of_Employment)
AND (#WeekEnding IS NULL OR Week_Ending = CONVERT(datetime, #WeekEnding, 103))
This query allows the user to filter by any one or combination of the 4 columns
This solution is working really well except for the issue that on the initial page load, as all 4 dropdownlists are set to the empty value it returns all results from the database, which takes a very long time due to the amount of data.
What i would like to be able to do is to prevent the gridview from showing any results on the initial page load, until one of the filters is applied. I know that instead of Blank value being default i could use some invalid data such as "Please select a filter" for each dropdownlist, but ideally i would like the user not to have to pick the blank option in each dropdownlist to select no filter, as a majority of queries are usually just a single filter or two.
Is there a simple way to stop the query before the initial page load, or a best practice for filtering with the dropdownlists that i am overlooking?
Thanks
Instead of programmatically moving the gridview bind to the datasource into the code behind, i have instead removed the SelectCommand from the datasource and added it programmatically on the first postback. That way my gridview still loads and displays my EmptyDataText value.
Dim dataSourceBindComplete As Boolean = False
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
If dataSourceBindComplete = False Then
dataSourceBindComplete.SelectCommand = "SELECT Week_Ending, Employee, Project, Status_Of_Employment FROM Times WHERE (#Project IS NULL OR Project LIKE #Project) AND (#Employee IS NULL OR Employee LIKE #Employee) AND (#Status_Of_Employment IS NULL OR Status_Of_Employment LIKE #Status_Of_Employment) AND (#WeekEnding IS NULL OR Week_Ending = CONVERT(datetime, #WeekEnding, 103))"
dataSourceBindComplete = True
End If
End If
End Sub
I actually have a Access database where i have a table called "tblfreight" and two column is there (items and Price)
And I want to auto show the Price when I choose Items.
There is two Textbox: "txtitems" and "txtprice"
I want to be like this....
If txtitems.text = select from tblfreight and column items Then
txtprice.text = select from tblfreight and column Price
Else txtprice.text=0 (Zero)
You need to query your DB first..
Select * from tblfreight - will get you your data you need.
Then you need to put this data somewhere. You can use a combobox for this. Once you have your combobox filled with your data you then can set the price into a label or textbox easily.
You can use the combobox selected index changed event...
Inside the changed event something like this would work...
textprice.text = Combobox.selecteditem.value
This will give you a great start, that's why this answer just gives you the steps and not the full code.
I have a VB report which contains a list of locations. I have this list separated into areas and I need to count the total number of rows per area section. I have a groupHeader which contains my area field, then in the group I list the corresponding entries for that area. Then in the groupFooter I would like to give the total number of entries in the group. How can I do this? I have two fields in my groupFooter
groupCount
groupTotalAmount
-this sums up a value I have in each entry. Any guidance would be appreciated.
ewein,
You can get the total records in a group by setting some properties in the designer itself. The simplest example would be using the NorthWind database. You bind your report to the Customers table and want the report to group on countries where each group will contain the cities for that particular country.
From your question I think you are already aware on how to get groups in a report, so I will only talk about getting the record count for each Group. Place a textbox in the GroupFooter. Set its datafield property to "Country" (same as that of groupheader). Now you need to set the following properties for the textbox:
SummaryFunction:- Count
SummaryGroup:- GroupHeader1 (or the groupheader name you have in your report)
SummaryRunning:- Group
SummaryType:- SubTotal
You can also get the same results programmatically by using the following code. Please note that "TextBox1" is the textbox used to display the count and is placed in the GroupFooter section:
Private count As Integer = 0
Public Sub GroupHeader1_Format()
count = 0
End Sub
Public Sub Detail1_Format()
count += 1
End Sub
Public Sub GroupFooter1_Format()
TextBox1.Text = count.ToString()
End Sub
I hope this will help you. You may also want to check the ActiveReports blogs where you can find blogs on various areas of interest.