VB.NET create (MS ACCESS like) "linked forms" - vb.net

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

Related

How to see name when I enter an id in access form

I have a Form where I Enter CustomerID in a combo box. This box has Two Columns CustomerID and CustName.
the CustName and CustFather reside in another query.
is there a way to show the CustName and CustFather everytime i enter CustomerID in the form?
The CustomerID is entered in a form and not in the same table as CustName and CustFather.
Tried DLookup but it just looks only the first time and then shows that same value everytime i open the form or update it. the dlookup is shown as:
=DLookUp("CustName","qryForRecovery","CustomerID =" & "CustomerID")
is there a way i can show the CustName everytime i update the CustomerID field?
This is the link to the snapshot of my recovery form.
https://i.stack.imgur.com/YzuxK.png
Use a combo box to enter the customerId.
Then create a text box for the customerName, that links to the customerId combo, as explained here.
The trick is to properly set the properties of the combo:
RowSource Type: Table/Query
Source: SELECT CustomerID, CompanyName FROM tblCustomers
Bound column: 1
Column count: 2
Limit to List: Yes
Column widths: 3;0 'second column will be hidden
You don't need Dlookups or whatever ..just correctly designed ComboBox
RowSource = SELECT CustomerID,CustName CustFath From Customers
Bound column: 1
Column count: 3
Column width : 0;4;4
You won't see the ID ..but Customer Name will be nicely displayed.

Inputting Data into Database and reading it

I have an SQL database and 2 VB applications, teacher and student application.
In the teacher application, the SQL database is connected with datagridview. In the form there are 10-15 checkboxes. those checkboxes are a set of weak points the teacher can select for a student in their class. for eg- "weak in calculations" etc. I want, when the teacher select the checkboxes, they should be shown in the teacher application in a string form. I think assigning each check box an ID would be a lot better than inputting long strings into the database. when the teacher selects a checkbox, the ID for that checkbox goes into the datagridview selected cell. I am not sure how to seperate each ID in the same cell because the teacher can select multiple checkboxes.
I need help with seperating the IDs and then reading them.
http://www.filedropper.com/sample_18 here is a sample program i made, it shows entering the checkbox id into the datagridview.
Let's keep it simple. Let's say we have 3 check boxes.
So for saving to db:
dim totalValue as integer = 0
if (chkBox1.checked) then totalValue +=1
if (chkBox1.checked) then totalValue +=2
if (chkBox1.checked) then totalValue +=4
save to db the totalValue
For reading from db:
totalValue = get this value from db
chkBox1.checked = ((totalValue and 1)=1)
chkBox1.checked = ((totalValue and 2)=2)
chkBox1.checked = ((totalValue and 4)=4)

Access 2010 VBA to Sort a Report with existing grouping

I have a Access 2010 report with two groups I set up in design. The first group has person data (name, dob, current address, customer points, date customer last placed a order). The second group has for the current person, all of their orders. The form that calls this report has a sort by option. They can sort by the name ascending or decending, the last date they ordered something asc/desc, and how many customer points they have asc/desc. All of these sort options should work on the data in the first/primary report group. Is there any way to call this report and set the orderby in VBA when the report already contains groups? I am passing in args from the form and trying on the load
Me.OrderBy = ArgIn(2)
Me.OrderByOn = True
I have also tried this in the open event. The report opens but ignores the sorting/order by.
Thanks
There are two routes you can go rather than passing arguments:
Create 3 exact same reports but with different sorting (within report design on group, you can sort the underlying items) and have a form trigger button with a drop down or list menu for user to select specific report ordering and then call the particular report.
In VBA, create a dynamic, user-defined querydef (Set qrydef = db.CreateQueryDef("[QUERY NAME]", strSQL) that is called by a form trigger button on a particular SQL statement out of three for each ORDER BY type (last name, date, points). Set the querydef to the report's recordsource.
The best dynamic way to do this is to use .SortOrder and .ControlSource:
Private Sub Report_Open(Cancel As Integer)
' Set SortOrder property to Ascending order (SortOrder = False)
Me.GroupLevel(0).SortOrder = blSortOrder
Me.GroupLevel(0).ControlSource = strSortBy
End Sub
.ControlSource is the field name of your reports table/query to be sorted. The filter hierarchy is addressed like Me.GroupLevel(0), Me.GroupLevel(1), Me.GroupLevel(2), etc..
Pass in this data via Me.OpenArgs.
Me.GroupLevel(0).SortOrder = Split(Me.OpenArgs, "|")(0)
Me.GroupLevel(0).ControlSource = Split(Me.OpenArgs, "|")(1)
Call the report like:
DoCmd.OpenReport "ReportName", acViewPreview, , , acWindowNormal, strSortBy & "|" & blSortOrder
...and make sure the sorted field is unique in its table, if you use grouping. (Notice that Access turns sorting into grouping when you add a header).

Display text corresponding to Combobox selection in Microsoft Access 2010

I have a contact form and one of the fields in a the form is a Contact_Type_ID. This field is a number field which also corresponds to a text field in another table (e.g. 1 = expatriate).
When I cycle through the contacts, their Contact_Type_ID is 1, 2, 3... instead of Non-profit, CEO, Vice-president, etc. This is a problem because one has no idea what number 3 means.
I would like to a combobox that only displays the corresponding text.
I can't get the two columns and 0;1 format to work. My hunch is that it's because I'm drawing information from two different tables. I can generate the correct list, but then the main entry doesn't change as I cycle through the contacts to reflect the current contact's [Contact_Type_ID].
I can't edit any of the current tables because I am supposed to apply this application to a much larger scale database.
I also tried setting the SQL for the row source:
'Populate the connection combo box '
Dim typeSQL As String
typeSQL = "SELECT DISTINCT Contacts.[ContactTypeID], Contact_Types.[ContactType] " & _
"FROM Contacts, Contact_Types " & _
"ORDER BY Contact_Types.[ContactType];"
Me.cbo_ContactType.RowSource = typeSQL
However, I then have the same problem: the combobox won't update as I cycle through the contacts. I don't understand the difference between the rowsource and the controlsource. I feel that this distinction might be key here.
Assuming I understand correctly:
In the combo box properties, go to the Data tab.
Set the Control Source to Contact_Type_ID.
This means that when you go through the records, the combo box will correspond to the Contact_Type_ID field from your data.
Set the Row Source to "SELECT Contacts.[ContactTypeID], Contact_Types.[ContactType] FROM Contacts, Contact_Types ORDER BY Contact_Types.[ContactType];"
The Row Source indicates the data that the combo box has access to, which will help it determine how to display the control source value.
Set the Bound Column to 1
Set Limit to List to Yes
Now in the Format tab. Change Column Count to 2.
Next set the column widths to the 0;1 you mentioned in your question.
Now try looking at form view, and it should behave as you expected.
If it does not work, create a new control with these instructions.
As I understand your question, you have a form with contacts based on a table Contacts and that table contains a field called either Contact_Type_ID or ContactTypeID. You wish to display the description of the contact type from a table Contact_Types.
You do not need to join tables for your combo, it should be very simple. The key, as you suspected, is the Control source, which is the property that relates one table to another.
Control source : ContactTypeID '' or Contact_Type_ID, choose from the list
Row source : SELECT ContactTypeID, ContactType FROM Contact_Types ORDER BY ContactType
Bound column : 1
Column count : 2
Column widths : 0,2
As an aside, you can join tables in a combo and still set the first column to 0 and it will still work, it is all in the correct set up.

What is the purpose of BOUND COLUMN property of listbox in MS Access?

What is the purpose of BOUND COLUMN property of listbox?
The bound column is a number that represents what column from the row source will be used to set the value of the Control Source (if the list box is bound).
Note that you can’t use a column name here. So you don't set the bound column to a column name, but you must use a column number.
Another issue here is that the column number starts at 1 (not zero). Note that OFTEN the 1st column length is set to zero. That allows you to have a list box with something like
select PartNumber, PartDescripton from tblParts
The list box will display the part description, but if you set the bound column = 1, then the listbox will return the PartNumber despite the fact that the listbox is displaying Descriptions (since you set the length of the 1st column = 0. If you set the bound column = 2, then the listbox will return description. Note that you can grab any column value from the list box by using
([lstBox1].Column)
Note that in the above, the column feature is zero based. So, 1 = 2nd column
It's the column of the data set that is used to set the value of the listbox. For example, if it's bound to a dataset with the query:
select firstname,lastname,userid from users;
then setting the bound column to userid (3 in the above example) will cause the user ID information to be returned as the listbox value.
A bound column is the data that the form is going to save. For instance, if you have a list box or combo box that lists employeeID and employeeName and you set the bound column to 0, the form will save the employee ID number from
the selection and insert that value into the corresponding table.
You can test which value you are referencing this using this vba:
Private Sub ComboBoxName_AfterUpdate()
MsgBox ("bound column is: " & Me.ComboBoxName.BoundColumn & ". value is: " & Me.ComboBoxName.Column(0))'change 0 to whatever number column is bound
End Sub
The bound column rule applies even if the first column is hidden on the form. For instance, the user could select "Mike Jones" from the employee list, but the form is going to save Mike Jones' employeeID for data uses (this ID could be stored in a table of sales records, etc.).