VBA code to delete records from subform and autopopulate fields in Main Form. (1 Viewer)

Local time
Today, 14:24
Joined
Jun 3, 2022
Messages
38
Hello. This may be confusing to explain but I'll try my best. I have a Main Form and Sub form. Main Form is frmEstimateBr and subform is subfrmEstimateBr.

When information is deleted from the subform, certain text boxes must autopopulate into the main form.

I have a Saved Record button in the Main Form that when a user clicks save, it performs the action of saving, and it reqrys back to the selected BrNumber. When the deletion of a record from the subform occurs, a requery of the selected BrNumber does not occur. I attached a picture to make it easier to see and the vba code below for the actions to work. Hope it understandable... struggling on this. I wanted to include a video but unable to.
 
Last edited:

June7

AWF VIP
Local time
Today, 11:24
Joined
Mar 9, 2014
Messages
5,470
Exactly how are you calculating the textboxes on main form?
If you want to provide db for analysis, follow instructions at bottom of my post.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:24
Joined
May 7, 2009
Messages
19,237
...
...
LResponse = MsgBox("Are you sure to Delete the Record(s) selected?", vbYesNo, "Delete Business Record")


If LResponse = vbYes Then
With Me.[SubfrmEstimateBr].Form.RecordsetClone
If Not (.BOF And .EOF) Then
.MoveFirst
End If
Do Until .EOF
.Delete
.MoveNext
Loop
End With
.
..
...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:24
Joined
May 7, 2009
Messages
19,237
there is some sort of corruption on your db.
i imported to new db.
it will now delete record from subform.
 

Attachments

  • Database3.accdb
    876 KB · Views: 136

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:24
Joined
Feb 19, 2002
Messages
43,266
it performs the action of saving, and it reqrys back to the selected BrNumber.
Saving a record using a proper method does NOT move the form off the current record. You are misusing the .Requery method. You should probably read the help entry on requery. Saving the current record is a side effect of its real task which is to rerun the query that the form is bound to. The side effect of that is that you lose your current position.

Deleting a subform record by using a button on the main form is extremely dangerous. Delete buttons, if you use them, belong on the row being deleted. You are assuming the user understands which record will be deleted even when it might not be currently visible on the subform.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:24
Joined
May 7, 2009
Messages
19,237
ok test it again.
 

Attachments

  • Database3.accdb
    1.5 MB · Views: 163

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:24
Joined
May 7, 2009
Messages
19,237
both the Main form and the subform is using Same Table?
you should make the Mainform Unbound.
 

June7

AWF VIP
Local time
Today, 11:24
Joined
Mar 9, 2014
Messages
5,470
Is this an effort to emulate a split form?
 

Users who are viewing this thread

Top Bottom