text box update problem

F

Fredrated

I am having a problem because a text box doesn't recognize data has been
typed into it until the cursor has been moved, but not always even then!

Long winded description follows.

We manage online training, and have started charging to reopen a class for
students that let their enrollment lapse, because so many of them do that.

The main management form has a payment subform to accept payment datails,
and a payment isn't considered valid unless all details needed for a specific
payment type are entered. For example, if the payment type is credit card,
the payment information is incomplete if there is no card expiration date
entered.

The 'reactivate enrollment' form is a non-modal pop up. The admin enters
details like how long to reactivate the enrollment for, then clicks
'reactivate'. If a valid payment has not been entered into the payment
subform, they get a message to that effect. So they stop the process, enter
a payment, then click 'reactivate' again.

The 'reactivate' popup queries the payment subform (it has unbound controls)
and asks if a valid payment has been entered. Here is where the problem
occurs. The user has entered the payer in the last payment subform text box.
The cursor is still blinking in this text box when the user clicks
'reactivate' on the popup again, and at this point, when the payment subform
is queried to see if it has valid payment information, it thinks the 'payer'
text box is still empty!

So (finally) the question is: is there some way to make the subform
recognize that all text boxes have data, without making the user click
somewhere else in the subform, something they wouldn't naturally do?
I tried preceeding the validity check with Me.txtPayer.Requery, but that
resulted in the error message 'You must save the current field before you run
the requery action', but there seems to be no Me.txtPayer.Save method.
Because the payment subform has unbound controls I can't docmd the command
that forces a record to be saved.

Any ideas? Thanks in advance for any help.

Fred
 
D

Dirk Goldgar

Fredrated said:
I am having a problem because a text box doesn't recognize data has been
typed into it until the cursor has been moved, but not always even then!

Long winded description follows.

We manage online training, and have started charging to reopen a class for
students that let their enrollment lapse, because so many of them do that.

The main management form has a payment subform to accept payment datails,
and a payment isn't considered valid unless all details needed for a
specific
payment type are entered. For example, if the payment type is credit
card,
the payment information is incomplete if there is no card expiration date
entered.

The 'reactivate enrollment' form is a non-modal pop up. The admin enters
details like how long to reactivate the enrollment for, then clicks
'reactivate'. If a valid payment has not been entered into the payment
subform, they get a message to that effect. So they stop the process,
enter
a payment, then click 'reactivate' again.

The 'reactivate' popup queries the payment subform (it has unbound
controls)
and asks if a valid payment has been entered. Here is where the problem
occurs. The user has entered the payer in the last payment subform text
box.
The cursor is still blinking in this text box when the user clicks
'reactivate' on the popup again, and at this point, when the payment
subform
is queried to see if it has valid payment information, it thinks the
'payer'
text box is still empty!

So (finally) the question is: is there some way to make the subform
recognize that all text boxes have data, without making the user click
somewhere else in the subform, something they wouldn't naturally do?
I tried preceeding the validity check with Me.txtPayer.Requery, but that
resulted in the error message 'You must save the current field before you
run
the requery action', but there seems to be no Me.txtPayer.Save method.
Because the payment subform has unbound controls I can't docmd the command
that forces a record to be saved.

Any ideas? Thanks in advance for any help.

Fred


When you say "the payment subform is queried to see if it has valid payment
information", what exactly do you mean? What is the code that performs this
check? I think I see what may be going on, but I'd like a bit more
information.
 
F

Fredrated

When you say "the payment subform is queried to see if it has valid payment
information", what exactly do you mean? What is the code that performs this
check? I think I see what may be going on, but I'd like a bit more
information.

The payment subform has the following:
Public Function PaymentPassesTest() As Boolean

Based on the data that the payment method requires, this function verifies
that all the data necessary for a valid payment is pesent in the text boxes,
or not as the case may be.

Other forms access this with code like:
If frmGetPayment.PaymentPassesTest = false then
if MsgBox("A valid payment was not entered." & vbcrlf & "Do you wish to
proceed anyway?", vbyesno) = vbno then GoTo Exit_ReactivateAccount
endif

Thanks for your interest.
 
D

Dirk Goldgar

Fredrated said:
The payment subform has the following:
Public Function PaymentPassesTest() As Boolean

Based on the data that the payment method requires, this function verifies
that all the data necessary for a valid payment is pesent in the text
boxes,
or not as the case may be.

Other forms access this with code like:
If frmGetPayment.PaymentPassesTest = false then
if MsgBox("A valid payment was not entered." & vbcrlf & "Do you wish to
proceed anyway?", vbyesno) = vbno then GoTo Exit_ReactivateAccount
endif


What I need to see is the code in the function, PaymentPassesTest(). I'm
going to guess that we need to modify it to force the update of whatever
control happens to be active, but I can't make a solid recommendation
without seeing the code.
 
F

Fredrated

What I need to see is the code in the function, PaymentPassesTest(). I'm
going to guess that we need to modify it to force the update of whatever
control happens to be active, but I can't make a solid recommendation
without seeing the code.

Duh! What was I thinking?
Here is the code for validating a payment.
First I check that a payment method was selected.
If it was selected, I look up it's record in the PaymentMethod table, which
tells me what data is required for each method:

Public Function PaymentPassesTest() As Boolean

Dim rs As Recordset
Dim strSQL As String

'was a payment method entered?
If IsNull(cboPaymentMethod) Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

PaymentPassesTest = True

strSQL = "SELECT PaymentMethods.RequireAmount,
PaymentMethods.RequirePayNumber, PaymentMethods.RequireExpDate,
PaymentMethods.RequirePayor, PaymentMethods.RequireDate FROM PaymentMethods
WHERE (((PaymentMethods.PaymentMethodID)=" & CStr(Me.cboPaymentMethod) & "));"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

rs.MoveFirst

'amount required?
If IsNull(txtPaymentAmount) And rs!RequireAmount = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'pay number required?
If IsNull(txtPayInstrumentNumber) And rs!RequirePayNumber = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'card expire date required?
If IsNull(txtCreditCardExpDate) And rs!RequireExpDate = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'payer required?
If IsNull(txtPayor) And rs!RequirePayor = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'pay date required?
If IsNull(txtPaymentDate) And rs!RequireDate = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

Exit_PaymentPassesTest:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Function


End Function
 
D

Dirk Goldgar

Fredrated said:
Duh! What was I thinking?
Here is the code for validating a payment.
First I check that a payment method was selected.
If it was selected, I look up it's record in the PaymentMethod table,
which
tells me what data is required for each method:

Public Function PaymentPassesTest() As Boolean

Dim rs As Recordset
Dim strSQL As String

'was a payment method entered?
If IsNull(cboPaymentMethod) Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

PaymentPassesTest = True

strSQL = "SELECT PaymentMethods.RequireAmount,
PaymentMethods.RequirePayNumber, PaymentMethods.RequireExpDate,
PaymentMethods.RequirePayor, PaymentMethods.RequireDate FROM
PaymentMethods
WHERE (((PaymentMethods.PaymentMethodID)=" & CStr(Me.cboPaymentMethod) &
"));"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

rs.MoveFirst

'amount required?
If IsNull(txtPaymentAmount) And rs!RequireAmount = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'pay number required?
If IsNull(txtPayInstrumentNumber) And rs!RequirePayNumber = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'card expire date required?
If IsNull(txtCreditCardExpDate) And rs!RequireExpDate = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'payer required?
If IsNull(txtPayor) And rs!RequirePayor = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

'pay date required?
If IsNull(txtPaymentDate) And rs!RequireDate = True Then
PaymentPassesTest = False
GoTo Exit_PaymentPassesTest
End If

Exit_PaymentPassesTest:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Function


End Function


Thanks. The way I see it, the problem is that, at the time the validation
code is run, you may have an uncommitted value in one of the required
controls. By "uncommitted value", I mean that the user has typed something
into the control, but Access has not yet updated the Value property of the
control. This can only be the case when the control still has the focus, as
is the case when you are calling the validation code from the popup form
while the cursor is still in the text box on the payment subform. In such a
situation, the Text property of the control has been updated by the user,
but the Value property of the control has not been updated by Access.

As I read the code, there could potentially be a variety of controls that
might have the same issue, so we want a solution that will work for all of
them. Try this:

'----- start of revised code (snippet) -----
Public Function PaymentPassesTest() As Boolean

Dim rs As Recordset
Dim strSQL As String

' Force Access to commit any uncommitted values.
On Error Resume Next ' Ignore error if no ActiveControl
Me.ActiveControl.Value = Me.ActiveControl.Text
On Error GoTo 0 ' Restore original error-handling

' ... remainder of code ...

End Function

'----- end of revised code (snippet) -----
 
F

Fredrated

Excellent! I added your code and tested it this morning and it worked
perfectly!
This is exactly what I was looking for.

Thank you for taking the time to look at my problem.

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top