Updating textbox populated by vba code (1 Viewer)

Kuleesha

Member
Local time
Today, 23:51
Joined
Jul 18, 2021
Messages
50
Hi,
I have a textbox on my form which is populated by VBA code. I want this details to be updated in a query as soon as I type in the data / by the time I move to the next textbox. A pop up form has to display the data in the query. I have placed the following code on the change event of the textbox. If I manually type in a value in the text box, the query gets updated but when it is populated by vba code after a calculation, it does not. Is there anyway that I can achieve what i want?

Code:
DoCmd.OpenQuery "qryCLCDDetail"
DoCmd.Requery
Forms!frmCLCDDetail.Requery
DoCmd.Close acQuery, "qryCLCDDetail", acSaveYes
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:21
Joined
Oct 29, 2018
Messages
21,454
In your VBA code to update the value, try adding a line to requery or refresh the query.
 

MarkK

bit cruncher
Local time
Today, 11:21
Joined
Mar 17, 2004
Messages
8,179
A common pattern if you have a ProcessC that you want to run from EventA AND EventB is to write a subroutine.
What you have now....
Code:
Private Sub EventA
    DoCmd.OpenQuery "qryCLCDDetail"
    DoCmd.Requery
    Forms!frmCLCDDetail.Requery
    DoCmd.Close acQuery, "qryCLCDDetail", acSaveYes
End Sub
A pattern that might help in this case...
Code:
Private Sub EventA
    ProcessC
End Sub

Private Sub EventB
    ProcessC
End Sub

Private Sub ProcessC
    DoCmd.OpenQuery "qryCLCDDetail"
    DoCmd.Requery
    Forms!frmCLCDDetail.Requery
    DoCmd.Close acQuery, "qryCLCDDetail", acSaveYes
End Sub
This is the fundamental idea of reusable code, that one process becomes available to multiple consumers.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:21
Joined
Feb 19, 2002
Messages
43,229
1. the Change event runs multiple times. Once for each character you type. That is probably not what you want. A better event to use is the AfterUpdate.
2. Code will not trigger events for unbound controls.
3. It is always easier for us if you explain what business process you are trying to mirror rather than asking us to just fix code in a procedure that doesn't really make any sense. The process seems like a Rube Goldberg device.
4. Why is the control unbound?
5. Are you actually running an update query on the current record or is it for a different record or different table?
 

Users who are viewing this thread

Top Bottom