(VB.NET Visual Studio 2019) How can I make a parent/child database work through multiple forms? - vb.net

I am creating forms in Visual Studio 2019 (using VB.Net) that is connected to a Microsoft Access Database.
From the image below, I have a parent form (i.e., Customer Database) with a key ID that is Customer Address. When I press the purchase history at the bottom, I can open a child form (i.e., Customer Purchase History). However, I do not know the specific code to write in the child form to filter the purchases for the current key ID.
In the example below, when I press "Purchase History", it shows the purchases of all customers and not of 1011 WESTON RD. The code that I currently use says
"Me.TblCustomerPurchaseHistoryTableAdapter.Fill(Me.CustdataDataSet.tblCustomerPurchaseHostory)"
Can anyone help me how to do the filtering for the child database? I will appreciate your help so much. Thank you!
enter image description here

First of all, you need a parameter to your table adapter. Click on your table adapter and select add query on your child form.
It will prompt out something like
Select Transdate, Customer,Qty,Price from CustomerPurchaseHistory (e.g)
then you add the parameter by extending the query
Select Transdate, Customer,Qty,Price from CustomerPurchaseHistory Where Customer = #Customer (e.g) and Name it as FillByCustomer on Top.
A new query will be created.
Then you probably have something like Me.TblCustomerPurchaseHistoryTableAdapter.FillByCustomer(Me.CustdataDataSet.tblCustomerPurchaseHostory, [Pass your customer Code here])
On your sub form
Declare a parameter something like
Public CustomerCode as string
(So that you can pass the parameter form your parent)
On your parent you can then do something like
frmChildform.show
frmChildform.CustomerCode = [Your selected custoemrcode]
After that on formload event on your childform just do something like
Me.TblCustomerPurchaseHistoryTableAdapter.FillByCustomer(Me.CustdataDataSet.tblCustomerPurchaseHostory, CustomerCode)

Related

Update control value on parent form when all values on subform are changed to a certain value

I am currently helping design a business case form in ACCESS 2013 for our department's product managers to facilitate them submit business cases and store data.
There is one subform on the parent form, which displays all SKUs associated with the business case in datasheet view, as well as their statuses (one SKU might be in stage 1, another in stage 2), and the parent/child form are linked by case ID. That is to say one case ID is associated with many SKUs. What I want to do is to update a field value (case status) on parent form only when all SKU statues are updated to stage 3. If one SKU is stage 3 but another one is in stage 2, then don't update the case status. I googled a lot however there doesn't seem to be a solution I can find online. Could anyone please help me?
Should not save this calculated value to table. Just calculate when needed.
A textbox on subform footer can have expression to count records where stage is not 3.
=Count(IIf(Stage<>3,1))
Textbox on main form can reference the subform textbox.
=IIf([subform container name]!tbxStageCount > 0, "Incomplete", "Complete")

MS Access manual Auto incrementing field

Im building a system for my company to keep track of internal orders, inbetween our warehouses, we have material that goes out warehouse 1 to warehouse 2 and we kind of lose track of how much of "x" is in warehouse 1 and how much in warehouse 2, so i want to implement this access db where a user fills a form and says: order 1: 500 of "x" order 2: 300 of "y". then another user fills an exit form where he says 1 of "x" going out, so i would need the program to keep track of total order and how much as gone out to fill order 1 and so on...
My idea here is to have both an order number and an id number for each of "x" everytime someoneone assembles 1 "x" they fill the form and print a label directly from the access (i have this part working already) while keeping a record of when it was assembled, who verified and what was verified (it will work as a quality control also).
What i dont know is how to program the db so when it reaches 500 of "x", the id number for "x" starts again from 1
This is the one major issue with my program right now, i'm not experienced in access db's or vba, but im getting there with a tip and a trick from here and there, so, no need to be careful with the technical language, i will google it if i have to :p
EDIT:
The table structure goes as follows:
1 table as the main table where I record the check that is made for every product, where I include the model of the product, the said ID that I want to reset after a number of products checked, and a concatenated field that includes most of this information to generate a qr code.
Then there is a table for the Order Number, which is connected to a form to record each new order with a date/time field, the order number itself and the number of products. This number of products must then be called from the code that will count how many products have been checked to date and keep the order number field updated so we can keep track of the order.
Then there is another minor table just to get values for the form, the product models
Thank you for your answers ;)
See this MSDN Documentation
Unfortunately in Access, you cannot 'reset' an ID field, unless you move the records to a newly created table and use that table for every 500 records.
As for the user control and login form, I'm afraid those are separate questions that must be asked in a different thread.
To get you started:
You can set the RecordSource of a form to a table, and when users make entries, the data will be saved to the table. You can also use a form with controls (text boxes, comboboxes, etc.) and create a button that runs a query to insert these records into a table.
The login piece - you can encrypt the database with a password. That may/may not be sufficient.
I would suggest you change your schema, if possible. Something like the following:
Orders
OrderID (Autonumber)
ProductID (link to your Products table)
QuantityRequested
Deliverables
DeliverableID (Autonumber)
OrderID (link to your Orders table)
SequenceNumber: in the BeforeInsert event set this value equal to:
DCount("*", "Deliverables", "OrderID=" & Me.OrderID) + 1
I'm assuming that your form has a control named OrderID that is bound to the OrderID field of the Deliverables table.
The code uses the DCount() function to get the count of all the other deliverables that have already been created for this order. If this is the first deliverable, DCount() will return 0. It then adds 1 to this count to get the sequence number of the next deliverable.
If the new SequenceNumber is greater than the quantity requested, you could display a message saying that the order has been filled and cancel the creation of the Deliverable record.
This is just one approach and it is not a complete solution. I'm assuming that once assigned a sequence number a deliverable cannot be deleted. You might need to make allowances for deliverables that get lost or damaged. You could incorporate a status field to the Deliverable table to deal with this, but you would still need to make a decision about what to do with the SequenceNumber.

Database Design: Line Items & Additional Items

I am looking for a solution or to be told it simply is not possible/good practice.
I currently have a database whereby I can create new orders and select from a lookup table of products that I offer. This works great for the most part but i would also like to be able to add random miscellaneous items to the order. For instance one invoice may read "End of Tenancy Clean" and the listed product but then have also an entry for "2x Lightbulb" or something to that effect.
I have tried creating another lookup table for these items but the problem is i don't want to have to pre-define every conceivable item before I can make orders. I would much prefer to be able to simply type in the Item and price when it is needed.
Is there any database design or workaround that can achieve this? Any help is greatly appreciated. FYI I am using Lightswitch 2012 if that helps.
One option I've seen in the past is a record in your normal items table labeled something like "Additional Service", and the application code will recognize this item and also require you to enter or edit a description to print with the invoice.
In the ERP system which we have at work, there is a flag in the parts table which allows one to change the description of the part in orders; in other words, one lists the part number in the order and then changes the description. This one off description is stored in a special table (called NONSTANDARD) which basically has two fields - an id field and the description. There is a field in the 'orderlines' table which stores the id of the record in the special table. Normally the value of this field will be 0, which means that the normal description of the part be displayed, but if it's greater than 0, then the description is taken from the appropriate row in the nonstandard table.
You mean something like this?
(only key attributes included, for brevity)

what editable control should i use to display my spreadsheet in a vb.net application?

I have a spreadsheet in excel with three headers:
Project Name
The name of a project i'm working on.
Requested Role
The job title/profession of the project employee. (example: mechanic, manager, engineer)
Name
The name of the employee.
When i click on the Person's name i want another page or tab (specific to this person) to appear showing details about them such as their name, job title, how long they worked, what project they are doing... etc. (similar to a Facebook profile)
When i click on the project name i want another page or tab (specific to this project) to appear showing details about it such as the requirements, the deadline, who is currently working on it... etc.
Furthermore, i would like to set up two levels of access:
Managers:
People who can add new information but not change or delete existing information
(write-only permissions)
Administrators:
People who can have full access to all information.
All highest level of access.
I don't know how i would go about displaying and/or organizing so much information in a vb.net application. if anyone could provide some suggestions as to some possible layouts of the GUI it would be greatly appreciated!
Additional Details:
For the specific pages i was thinking of using the tab control but i want it so that i can search through the list of projects or names, select one, and then it brings up the page about it.
The levels of access is the least of my worries... although it is still a worry.
You don't want to store that information in an excel spreadsheet, a database is much, much better. For what you've described here I'm going to assume that you have Projects and Employees, and that multiple Employees can work on a project. You'll need a few tables then:
Project
ProjectSeq 'Int - unique sequence for this project record
Name 'String - name of project
Descr 'String - description of project
... 'Various - other fields as needed
Employee
EmployeeSeq 'Int - unique sequence for this employee record
Name 'String - Name of employee
Title 'String - Job title of this employee
IsManager 'Boolean - Is this employee a manager?
IsAdmin 'Boolean - Is this employee an administrator?
... 'Various - other fields as needed
ProjEmpl
ProjEmplSeq 'Int - unique sequence for this project-employee record
ProjSeq 'Int - link to project record
EmployeeSeq 'Int - link to employee record
... 'Various - other fields that apply to this project-employee combination
Once you have your tables all set up and populated with data, you'll want to read the data and transfer it to your .NET application. There are a few ways of doing this, you'll have to decide which works best for your needs. I'm a big fan of DataSets, they always work nicely.
To fill the grid, you'll need to use a sql statement that fills a datatable from the three tables (I'm using notepad as my IDE, so this may not be exact):
SELECT pe.*, p.Name as ProjName, e.Name as EmplName, e.Title
FROM ProjEmpl pe, Project p, Employee e
WHERE p.ProjectSeq = pe.ProjectSeq AND
e.EmployeeSeq = pe.EmployeeSeq
To display the data to the end user, you would use a DataGridView control. Set the datagrid.DataSource to use the datatable you just populated and the data should show up.
To display the related Employee & Project information, I'd use a tab control underneath the datagrid. One tab for Project, and one tab for Employee. Use individual controls for each field in the table. When the user changes rows in the datagrid, load the related Project and Employee information for that row into two datatables and populate the controls from that.
Lastly, to set permissions on the program you'll need to have the employee log onto the application. Once they've logged on you can look them up in the Employee table, find out if they are a manager or an administrator, and set the permissions accordingly.

Dynamic List Box In A Form

This question involves 3 tables and 1 form in my Access database.
The tables are:
- Contacts
- Customers
- Contacts to Customers Relationship
The form is:
- Manage Contact
What I want. A list box that displays the output of this SQL query:
SELECT Customers.AccountName FROM Customers INNER JOIN [Contacts to Customers Relationship] ON Customers.MasAccountNumber=[Contacts to Customers Relationship].MasAccountNumber WHERE [Contacts to Customers Relationship].ID = 3 ORDER BY Customers.AccountName;
Where you see the "3" in the above SQL statement I would like to have a dynamic value there. Something that references the current records value for the ID column (Contacts table). If I have to do this in a VB script adjusting the list boxes RowSource where would I do that? onLoad for the form doesn't seem to make sense because when someone clicks to change records or add a new record I want it to update for that "Contact" (record).
Any help is appreciated.
TW
The resolution to this lies in using the forms Current() method. That causes the form to re-execute the query that is bound in the RowSource property for that list box each time a different record is accessed in the form.
Thank you for your response Mr. Fenton.