With On Enter event, value is not being retrieved from a table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Entering data in a form, field is unbound. When I tab/enter into the field
and exit the field, the value is still not populated. 'Sometimes', if I
click on the field the value shows up. What's going on? The code is below:

Private Sub BeginBalance_Enter()
On Error GoTo BeginBalance_Enter_Err
Dim rs As Recordset
DoCmd.OpenQuery "QuerytoPopulateTablewithTotalNet", acViewNormal, acReadOnly
Set rs = CurrentDb.OpenRecordset("Select * From [TableContainingTotalNet]",
dbOpenDynaset) ' only a single record
With rs
[BeginBalance] = ![TotalNet] ' Get Balance from TableContainingTotalNet
End With
BeginBalance_Enter_Exit:
Exit Sub
BeginBalance_Enter_Err:
MsgBox Error$
Resume BeginBalance_Enter_Exit
End Sub

Would it be best to get the value straight from the query? If this is the
"best" approach, then how?
 
You're running an action query to do something to a record in
TableContainingTotalNet table, and then want to get that new value from that
table?

Not sure why you need to do this via an action query and then go get the
value.

My guess is that there is a timing issue involved here. Why do you want to
use the Enter event of the control? What if the person "skips" that control?
Surely there must be some other event that would also accomplish this for
you?

Perhaps you can tell us what you're trying to do and then we can help you
design the best way to achieve it.
 
The user is entering the sales data for the current day. After the user
enters the sales date, the Begin Balance can be calculated (based of previous
sales data) .
So my idea was when the user On Enters the Begin Balance field the balance
would appear. For example:

Sales Date
Begin Balance (calculated based on previous SalesData)
SalesData1
SalesData2
Ending Balance

Ken Snell said:
You're running an action query to do something to a record in
TableContainingTotalNet table, and then want to get that new value from that
table?

Not sure why you need to do this via an action query and then go get the
value.

My guess is that there is a timing issue involved here. Why do you want to
use the Enter event of the control? What if the person "skips" that control?
Surely there must be some other event that would also accomplish this for
you?

Perhaps you can tell us what you're trying to do and then we can help you
design the best way to achieve it.

--

Ken Snell
<MS ACCESS MVP>


jsccorps said:
Entering data in a form, field is unbound. When I tab/enter into the
field
and exit the field, the value is still not populated. 'Sometimes', if I
click on the field the value shows up. What's going on? The code is
below:

Private Sub BeginBalance_Enter()
On Error GoTo BeginBalance_Enter_Err
Dim rs As Recordset
DoCmd.OpenQuery "QuerytoPopulateTablewithTotalNet", acViewNormal,
acReadOnly
Set rs = CurrentDb.OpenRecordset("Select * From
[TableContainingTotalNet]",
dbOpenDynaset) ' only a single record
With rs
[BeginBalance] = ![TotalNet] ' Get Balance from
TableContainingTotalNet
End With
BeginBalance_Enter_Exit:
Exit Sub
BeginBalance_Enter_Err:
MsgBox Error$
Resume BeginBalance_Enter_Exit
End Sub

Would it be best to get the value straight from the query? If this is the
"best" approach, then how?
 
Try using the AfterUpdate event of the sales date control. Or, if you want
to be sure that the user is satisfied with the date entered, use the Exit
event of the sales date control.

You might try inserting
DoEvents

as a code step after the OpenQuery step too; that may help with timing.

--

Ken Snell
<MS ACCESS MVP>

jsccorps said:
The user is entering the sales data for the current day. After the user
enters the sales date, the Begin Balance can be calculated (based of
previous
sales data) .
So my idea was when the user On Enters the Begin Balance field the balance
would appear. For example:

Sales Date
Begin Balance (calculated based on previous SalesData)
SalesData1
SalesData2
Ending Balance

Ken Snell said:
You're running an action query to do something to a record in
TableContainingTotalNet table, and then want to get that new value from
that
table?

Not sure why you need to do this via an action query and then go get the
value.

My guess is that there is a timing issue involved here. Why do you want
to
use the Enter event of the control? What if the person "skips" that
control?
Surely there must be some other event that would also accomplish this for
you?

Perhaps you can tell us what you're trying to do and then we can help you
design the best way to achieve it.

--

Ken Snell
<MS ACCESS MVP>


jsccorps said:
Entering data in a form, field is unbound. When I tab/enter into the
field
and exit the field, the value is still not populated. 'Sometimes', if
I
click on the field the value shows up. What's going on? The code is
below:

Private Sub BeginBalance_Enter()
On Error GoTo BeginBalance_Enter_Err
Dim rs As Recordset
DoCmd.OpenQuery "QuerytoPopulateTablewithTotalNet", acViewNormal,
acReadOnly
Set rs = CurrentDb.OpenRecordset("Select * From
[TableContainingTotalNet]",
dbOpenDynaset) ' only a single record
With rs
[BeginBalance] = ![TotalNet] ' Get Balance from
TableContainingTotalNet
End With
BeginBalance_Enter_Exit:
Exit Sub
BeginBalance_Enter_Err:
MsgBox Error$
Resume BeginBalance_Enter_Exit
End Sub

Would it be best to get the value straight from the query? If this is
the
"best" approach, then how?
 
AfterUpdate event worked great!

thanks

Ken Snell said:
Try using the AfterUpdate event of the sales date control. Or, if you want
to be sure that the user is satisfied with the date entered, use the Exit
event of the sales date control.

You might try inserting
DoEvents

as a code step after the OpenQuery step too; that may help with timing.

--

Ken Snell
<MS ACCESS MVP>

jsccorps said:
The user is entering the sales data for the current day. After the user
enters the sales date, the Begin Balance can be calculated (based of
previous
sales data) .
So my idea was when the user On Enters the Begin Balance field the balance
would appear. For example:

Sales Date
Begin Balance (calculated based on previous SalesData)
SalesData1
SalesData2
Ending Balance

Ken Snell said:
You're running an action query to do something to a record in
TableContainingTotalNet table, and then want to get that new value from
that
table?

Not sure why you need to do this via an action query and then go get the
value.

My guess is that there is a timing issue involved here. Why do you want
to
use the Enter event of the control? What if the person "skips" that
control?
Surely there must be some other event that would also accomplish this for
you?

Perhaps you can tell us what you're trying to do and then we can help you
design the best way to achieve it.

--

Ken Snell
<MS ACCESS MVP>


Entering data in a form, field is unbound. When I tab/enter into the
field
and exit the field, the value is still not populated. 'Sometimes', if
I
click on the field the value shows up. What's going on? The code is
below:

Private Sub BeginBalance_Enter()
On Error GoTo BeginBalance_Enter_Err
Dim rs As Recordset
DoCmd.OpenQuery "QuerytoPopulateTablewithTotalNet", acViewNormal,
acReadOnly
Set rs = CurrentDb.OpenRecordset("Select * From
[TableContainingTotalNet]",
dbOpenDynaset) ' only a single record
With rs
[BeginBalance] = ![TotalNet] ' Get Balance from
TableContainingTotalNet
End With
BeginBalance_Enter_Exit:
Exit Sub
BeginBalance_Enter_Err:
MsgBox Error$
Resume BeginBalance_Enter_Exit
End Sub

Would it be best to get the value straight from the query? If this is
the
"best" approach, then how?
 
Back
Top