I am using Access 2010. I have a database that consists of bookings, receipts, clients and so on. I have made a form for booking tickets. The first field I have on my form is a combobox where a user can choose the username. And the second (receiptID) field should be filled automatically after the user has chosen appropriate username. I have an idea how to fill that field but what i don't have are the skills.
My Receipts table has these fields: receiptID, userID, cost, stateID, workerID
receiptID - Primary key
userID - Foreign key that points to the user this receipt is linked with
cost - shows the total cost of all bookings connected to this receipt
stateID - shows the current state of this receipt(1-in creation,2-created, 3-paid, 4-cancelled)
workerID - points to the accountant that signs the receipt
What i want to do is to fill the receiptID field on the form this way that if the selected user has any receipts in "in creation" state then the receiptID of that receipt is put there, but if there is no such receipt then new receipt is created and its receiptID is put there. I think I have to use SQL query in VBA to find the receiptID that satisfies the given conditions and if there aren't any results then new record will be created into Receipts table. I managed to create new record using VBA but at the moment every time I make a booking new record is created into Receipts table and that's not what I intended to do.
This is what I have right now for creating new record in Receipts table.
Query looks like this:
My Receipts table has these fields: receiptID, userID, cost, stateID, workerID
receiptID - Primary key
userID - Foreign key that points to the user this receipt is linked with
cost - shows the total cost of all bookings connected to this receipt
stateID - shows the current state of this receipt(1-in creation,2-created, 3-paid, 4-cancelled)
workerID - points to the accountant that signs the receipt
What i want to do is to fill the receiptID field on the form this way that if the selected user has any receipts in "in creation" state then the receiptID of that receipt is put there, but if there is no such receipt then new receipt is created and its receiptID is put there. I think I have to use SQL query in VBA to find the receiptID that satisfies the given conditions and if there aren't any results then new record will be created into Receipts table. I managed to create new record using VBA but at the moment every time I make a booking new record is created into Receipts table and that's not what I intended to do.
This is what I have right now for creating new record in Receipts table.
Code:
Set dbTeater = CurrentDb Set rsReceipts = dbTeater.OpenRecordset("Receipts") rsReceipts.AddNew rsReceipts("userID").Value = Me!Client rsReceipts("stateID").Value = 1 rsReceipts.Update
Code:
SELECT Receipts.receiptID FROM Receipts WHERE Receipts.userID=Forms!BookingsF!ClientBox AND Receipts.stateID=1
Comment