Hello there,
I encountered a problem after I tried to fix an annoying bug in my program.
I hope you guys can help me out with this.
Setup:
Mainform INCOME is setup with a couple of controls where I can select a customer and put in stuff like cash money and date.
Next there are a couple (3) subforms in the mainform.
One of them is for adding RENT, one for checking the history of already created records, and one for other sold stuff.
Now, when the company the program is for, selected a customer in the mainform, and did or did not put in other values in the controls on the main form, then switched over to the subform to add rent, right at that moment access created a record in the table bound to the mainform.
That was a problem, since most of the time, users selected a customer on the main form, and added rent on the subform, and not putting any other values in the controls on the mainform.
Now the incomes table consisted of 2 rows added:
1. A row with the selected customer, and nothing else
2. A row with the selected customer, nothing else, and a relation to the RENTS table, since they added rents.
No problems thusfar you think.
Well, the problem is, the first row added was a blank row.
It has no relations with other tables, and no other info next to the customers name.
Why adding the relation to the RENTS table to a new row?
That is because of the setup my program uses. Has something to do with adding the rent first to a temporary table, then, after save, adding it to the normal table. Really dont want to change that, a lot of the rest of my program needs this style.
Solution?
To prevent access from saving the mainform (since that is happening when the user switched over to the subform), I added some code:
Above code is from the MAINFORM and makes a variable used in the next code
Above code is from the MAINFORM and prevents saving when the user activates the subform
This is part of the save button.
Problem:
I want the Mainform only to save when the user presses the cmdSave button, and not when the user will click on the subform.
But, when the cancel event is fired, nothing in the subform will work anymore. It doesnt save the mainform, that worked, but no button, controls or something in the subform will work.
So is there some command that cancels the saving of the mainform, but then continue working with the form and subforms like no (trying to)save has ever happened?
I hope someone understands the story above. English is not my native language so if there is any more explanation needed I am willing to provide that
Thanks in advance
I encountered a problem after I tried to fix an annoying bug in my program.
I hope you guys can help me out with this.
Setup:
Mainform INCOME is setup with a couple of controls where I can select a customer and put in stuff like cash money and date.
Next there are a couple (3) subforms in the mainform.
One of them is for adding RENT, one for checking the history of already created records, and one for other sold stuff.
Now, when the company the program is for, selected a customer in the mainform, and did or did not put in other values in the controls on the main form, then switched over to the subform to add rent, right at that moment access created a record in the table bound to the mainform.
That was a problem, since most of the time, users selected a customer on the main form, and added rent on the subform, and not putting any other values in the controls on the mainform.
Now the incomes table consisted of 2 rows added:
1. A row with the selected customer, and nothing else
2. A row with the selected customer, nothing else, and a relation to the RENTS table, since they added rents.
No problems thusfar you think.
Well, the problem is, the first row added was a blank row.
It has no relations with other tables, and no other info next to the customers name.
Why adding the relation to the RENTS table to a new row?
That is because of the setup my program uses. Has something to do with adding the rent first to a temporary table, then, after save, adding it to the normal table. Really dont want to change that, a lot of the rest of my program needs this style.
Solution?
To prevent access from saving the mainform (since that is happening when the user switched over to the subform), I added some code:
Code:
Private Sub Form_Load()
[INDENT]Dim iCanSave As Boolean[/INDENT]
End Sub
Above code is from the MAINFORM and makes a variable used in the next code
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (iCanSave) Then
Cancel = True
End If
End Sub
Above code is from the MAINFORM and prevents saving when the user activates the subform
Code:
Private Sub cmdSave_Click()
iCanSave = True
DoCmd.RunCommand acCmdSaveRecord
End Sub
This is part of the save button.
Problem:
I want the Mainform only to save when the user presses the cmdSave button, and not when the user will click on the subform.
But, when the cancel event is fired, nothing in the subform will work anymore. It doesnt save the mainform, that worked, but no button, controls or something in the subform will work.
So is there some command that cancels the saving of the mainform, but then continue working with the form and subforms like no (trying to)save has ever happened?
I hope someone understands the story above. English is not my native language so if there is any more explanation needed I am willing to provide that
Thanks in advance