Tab Key on Primary form with Subform

G

GB

I have a primary form that has a subform on it. On the primary form I have
two unbound controls. 1 is a combo box that pulls data from a table, the
other is a "text" box that I filter for numbers only (and the delete key).
When data is entered into both of the boxes, then the data is used to search
for the matching record in the primary form, and subsequently the multiple
items are pulled into the subform that correspond to the primary form data.

The problem I have is that when I have completed typing the last of the
information in the text box and press the tab key to move to my button that
does additional work on the data, the focus does not move to the button until
I press the tab key a second time. This occurs if the data of the text box
has changed from the previous data. If I enter the text, press the tab, then
delete the information in the text box and retype it in exactly as it was
originally and then press the tab key, it will go directly to the next
control (my button that I want to then click). Also if I complete typing the
data (changed from the previous entry) then click directly on the button
without first tabbing (or clicking) away from the text box, then it performs
actions on the form, but with bad effects.

What is going on here, and how do I make it move to the next control after
updating the data in my fields?

This "same" code works fine when I don't have a subform, so I'm thinking
that it has something to do with refreshing the subform data. I created the
code of this form from a previous working one, though I didn't copy the
entire form and then modify the code. So wondering if there is some setting
on either the primary or subform that is causing the problem. Access Version
is 2003.

Thank you for any assistance.
 
G

GB

The code of my primary form contains the following:
TxfrNumber is a number field, and TxfrDesignation is a text field, but is
list limited. The fields are arranged on screen and in tab order to go from
TxfrDesignation to TxfrNumber; however, I have written the code to require
both to be filled in.

The button is called btnAddUp, and if the data already exists in the
subform, I erase the data and then add the new data by calling Add Data.
(Could be that the number of items is reduced so I start from scratch in that
section.) If the data does not exist in the subform then I add it. These
two functions work successfully if I use the tab key twice or click away from
the control (not to include clicking on the button) and then click on the
button. :\


Private Sub txtOpNum_AfterUpdate()
Dim rs As Object
Dim I As Long



Set rs = Me.Recordset.Clone
If Not IsNull(Me![cmbTxfrList]) Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""

Else
End If

If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Private Sub cmbTxfrList_AfterUpdate()
Dim rs As Object


Set rs = Me.Recordset.Clone

If IsNull(Me![txtOpNum]) Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "'"
Else
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""
End If

If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Private Sub txtOpNum_KeyPress(KeyAscii As Integer)
Dim strCharacter As String

strCharacter = Chr(KeyAscii)

If KeyAscii = 9 Then
MsgBox ("Tab pressed")
End If

If Not IsNumeric(strCharacter) And (KeyAscii < 8 Or KeyAscii > 9) Then
KeyAscii = 0
End If

End Sub


Private Sub btnAddUp_Click()
Dim rs As Object
Dim stDocName As String
Dim stLinkCriteria As String

Set rs = Me.Recordset.Clone

If (Not IsNull(Me![txtOpNum]) Or Me![txtOpNum] <> "") And (Not
IsNull(Me![cmbTxfrList]) Or Me![cmbTxfrList] <> "") Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""

If rs.NoMatch Then
MsgBox ("Going to Add.")
btnAdd_Click
Else
MsgBox ("Going to update.")
btnUpdate_Click
End If

End If

End Sub
 
G

GB

So I revisited my previous form that is working when I press the tab key, and
I discovered something. I don't really have an after update command that
does anything (like looking for records) when finished typing text in the
text box. I do all my record lookups when I click the command button that
does actions.

Thinking back as to why I did what I did, well, for my new form, I wanted to
see the data as I was updating so that I could prevent/correct data lookup
discrepancies. Although I am not finished with that testing, at least I have
an idea of how to "correct" it when I am done with the data update, and until
then, need to just keep trudging along using the double tab to move to the
next field and ensure that the command button will do the lookups that the
individual afterupdates do.

Therefore am not sure if I have corrected my problem or not, but at least
have a way around it. :)

GB said:
The code of my primary form contains the following:
TxfrNumber is a number field, and TxfrDesignation is a text field, but is
list limited. The fields are arranged on screen and in tab order to go from
TxfrDesignation to TxfrNumber; however, I have written the code to require
both to be filled in.

The button is called btnAddUp, and if the data already exists in the
subform, I erase the data and then add the new data by calling Add Data.
(Could be that the number of items is reduced so I start from scratch in that
section.) If the data does not exist in the subform then I add it. These
two functions work successfully if I use the tab key twice or click away from
the control (not to include clicking on the button) and then click on the
button. :\


Private Sub txtOpNum_AfterUpdate()
Dim rs As Object
Dim I As Long



Set rs = Me.Recordset.Clone
If Not IsNull(Me![cmbTxfrList]) Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""

Else
End If

If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Private Sub cmbTxfrList_AfterUpdate()
Dim rs As Object


Set rs = Me.Recordset.Clone

If IsNull(Me![txtOpNum]) Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "'"
Else
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""
End If

If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Private Sub txtOpNum_KeyPress(KeyAscii As Integer)
Dim strCharacter As String

strCharacter = Chr(KeyAscii)

If KeyAscii = 9 Then
MsgBox ("Tab pressed")
End If

If Not IsNumeric(strCharacter) And (KeyAscii < 8 Or KeyAscii > 9) Then
KeyAscii = 0
End If

End Sub


Private Sub btnAddUp_Click()
Dim rs As Object
Dim stDocName As String
Dim stLinkCriteria As String

Set rs = Me.Recordset.Clone

If (Not IsNull(Me![txtOpNum]) Or Me![txtOpNum] <> "") And (Not
IsNull(Me![cmbTxfrList]) Or Me![cmbTxfrList] <> "") Then
rs.FindFirst "[TxfrDesignation] = '" & Me![cmbTxfrList] & "' AND
[TxfrNumber] = " & Me![txtOpNum] & ""

If rs.NoMatch Then
MsgBox ("Going to Add.")
btnAdd_Click
Else
MsgBox ("Going to update.")
btnUpdate_Click
End If

End If

End Sub

GB said:
I have a primary form that has a subform on it. On the primary form I have
two unbound controls. 1 is a combo box that pulls data from a table, the
other is a "text" box that I filter for numbers only (and the delete key).
When data is entered into both of the boxes, then the data is used to search
for the matching record in the primary form, and subsequently the multiple
items are pulled into the subform that correspond to the primary form data.

The problem I have is that when I have completed typing the last of the
information in the text box and press the tab key to move to my button that
does additional work on the data, the focus does not move to the button until
I press the tab key a second time. This occurs if the data of the text box
has changed from the previous data. If I enter the text, press the tab, then
delete the information in the text box and retype it in exactly as it was
originally and then press the tab key, it will go directly to the next
control (my button that I want to then click). Also if I complete typing the
data (changed from the previous entry) then click directly on the button
without first tabbing (or clicking) away from the text box, then it performs
actions on the form, but with bad effects.

What is going on here, and how do I make it move to the next control after
updating the data in my fields?

This "same" code works fine when I don't have a subform, so I'm thinking
that it has something to do with refreshing the subform data. I created the
code of this form from a previous working one, though I didn't copy the
entire form and then modify the code. So wondering if there is some setting
on either the primary or subform that is causing the problem. Access Version
is 2003.

Thank you for any assistance.
 

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