redirecting the focus when a 'no match' condition is incurred.

T

The Old Guy

You folks have always been there in the past with the right answer and I hope
you can help again. I'm trying to stop processing when a NoMatch condition
is encounterd, redirecting the focus back to the input text box. I'm lost.
Any help??
thanks in advance.


Private Sub Text6_AfterUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
'this is where I'm stuck. how do I get the focus sent
'back to text6? everything I try still ends up with the
'cursor going to the next control. this code finds the
'inventory item as long as there is a match. I know
'the solution is probably simple, but then again, I'm
'teaching myself how to work with access.
End If
End If

End Sub
 
P

Paolo

Hi Old Guy,
you must put your code in the beforeupdate event of your text box, otherwise
you cannot stop the tabbing to the next control.
So that do as follow

Private Sub Text6_BeforeUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
Cancel=true
'In this way you cancel the event and the focus remain in text6
End If
End If

End Sub

HTH Paolo
 
K

Klatuu

You are partially correct. It does go in the Before Update event, but you
did not cancel the update if the control is empty. It should be:

Private Sub Text6_BeforeUpdate(Cancel As Integer)
Const MsgA As String = "Item Not Found! Verify and re-enter."
Const StylyeA As Long = vbOKOnly + vbExclamation
Const TitleA As String = "Item Data Error"

'checking for an empty text block
If Nz(Me.Text6,0) = 0 Then
MsgBox "Entery Required"
Cancel = True
Exit Sub
End If

' Find the record that matches the control.
With Me.RecordsetClone
.FindFirst "[Item] = """ & Me![Text6] & """"
If .NoMatch Then
MsgBox MsgA, StyleA, TitleA
Cancel=true
Else
Me.Bookmark = .Bookmark
End If
End With
End Sub
--
Dave Hargis, Microsoft Access MVP


Paolo said:
Hi Old Guy,
you must put your code in the beforeupdate event of your text box, otherwise
you cannot stop the tabbing to the next control.
So that do as follow

Private Sub Text6_BeforeUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
Cancel=true
'In this way you cancel the event and the focus remain in text6
End If
End If

End Sub

HTH Paolo

The Old Guy said:
You folks have always been there in the past with the right answer and I hope
you can help again. I'm trying to stop processing when a NoMatch condition
is encounterd, redirecting the focus back to the input text box. I'm lost.
Any help??
thanks in advance.


Private Sub Text6_AfterUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
'this is where I'm stuck. how do I get the focus sent
'back to text6? everything I try still ends up with the
'cursor going to the next control. this code finds the
'inventory item as long as there is a match. I know
'the solution is probably simple, but then again, I'm
'teaching myself how to work with access.
End If
End If

End Sub
 
K

Klatuu

Sorry, Paolo, the coffee kicked in and I realized why there is no cancel for
an empty text box. You need to be able to get out of the text box if no
entry is made. My bad.

Private Sub Text6_BeforeUpdate(Cancel As Integer)
Const MsgA As String = "Item Not Found! Verify and re-enter."
Const StylyeA As Long = vbOKOnly + vbExclamation
Const TitleA As String = "Item Data Error"

'checking for an empty text block
If Nz(Me.Text6,0) <> 0 Then
Exit Sub
End If

' Find the record that matches the control.
With Me.RecordsetClone
.FindFirst "[Item] = """ & Me![Text6] & """"
If .NoMatch Then
MsgBox MsgA, StyleA, TitleA
Cancel=true
Else
Me.Bookmark = .Bookmark
End If
End With
End Sub

--
Dave Hargis, Microsoft Access MVP


Paolo said:
Hi Old Guy,
you must put your code in the beforeupdate event of your text box, otherwise
you cannot stop the tabbing to the next control.
So that do as follow

Private Sub Text6_BeforeUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
Cancel=true
'In this way you cancel the event and the focus remain in text6
End If
End If

End Sub

HTH Paolo

The Old Guy said:
You folks have always been there in the past with the right answer and I hope
you can help again. I'm trying to stop processing when a NoMatch condition
is encounterd, redirecting the focus back to the input text box. I'm lost.
Any help??
thanks in advance.


Private Sub Text6_AfterUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
'this is where I'm stuck. how do I get the focus sent
'back to text6? everything I try still ends up with the
'cursor going to the next control. this code finds the
'inventory item as long as there is a match. I know
'the solution is probably simple, but then again, I'm
'teaching myself how to work with access.
End If
End If

End Sub
 
T

The Old Guy

Howdy,

Thanks for the reply. I knew it would be simple, but, the old brain cells
are getting hard with age so I do appreciate the help. Installed your
suggestion and it worked like a champ. Thanks again.


Paolo said:
Hi Old Guy,
you must put your code in the beforeupdate event of your text box, otherwise
you cannot stop the tabbing to the next control.
So that do as follow

Private Sub Text6_BeforeUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
Cancel=true
'In this way you cancel the event and the focus remain in text6
End If
End If

End Sub

HTH Paolo

The Old Guy said:
You folks have always been there in the past with the right answer and I hope
you can help again. I'm trying to stop processing when a NoMatch condition
is encounterd, redirecting the focus back to the input text box. I'm lost.
Any help??
thanks in advance.


Private Sub Text6_AfterUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
'this is where I'm stuck. how do I get the focus sent
'back to text6? everything I try still ends up with the
'cursor going to the next control. this code finds the
'inventory item as long as there is a match. I know
'the solution is probably simple, but then again, I'm
'teaching myself how to work with access.
End If
End If

End Sub
 
T

The Old Guy

Howdy, Thanks for the additional help. as i told Paolo, the old brain cells
are getting hard with age so any help is appreciated. Folks like you are
appreciated by all. Thanks again and keep sipping coffee often. Cheers!

John (AKA The old guy)


Klatuu said:
Sorry, Paolo, the coffee kicked in and I realized why there is no cancel for
an empty text box. You need to be able to get out of the text box if no
entry is made. My bad.

Private Sub Text6_BeforeUpdate(Cancel As Integer)
Const MsgA As String = "Item Not Found! Verify and re-enter."
Const StylyeA As Long = vbOKOnly + vbExclamation
Const TitleA As String = "Item Data Error"

'checking for an empty text block
If Nz(Me.Text6,0) <> 0 Then
Exit Sub
End If

' Find the record that matches the control.
With Me.RecordsetClone
.FindFirst "[Item] = """ & Me![Text6] & """"
If .NoMatch Then
MsgBox MsgA, StyleA, TitleA
Cancel=true
Else
Me.Bookmark = .Bookmark
End If
End With
End Sub

--
Dave Hargis, Microsoft Access MVP


Paolo said:
Hi Old Guy,
you must put your code in the beforeupdate event of your text box, otherwise
you cannot stop the tabbing to the next control.
So that do as follow

Private Sub Text6_BeforeUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
Cancel=true
'In this way you cancel the event and the focus remain in text6
End If
End If

End Sub

HTH Paolo

The Old Guy said:
You folks have always been there in the past with the right answer and I hope
you can help again. I'm trying to stop processing when a NoMatch condition
is encounterd, redirecting the focus back to the input text box. I'm lost.
Any help??
thanks in advance.


Private Sub Text6_AfterUpdate()
Dim rs As Object
Dim MsgA, StyleA, TitleA, Response

MsgA = "Item Not Found! Verify and re-enter." _

'-----------------------------------------------
'text6 is the input control for the item number
'-----------------------------------------------

StyleA = vbOKOnly + vbExclamation
TitleA = "Item Data Error"

'checking for an empty text block
If IsNull(Me.Text6) Or Me.Text6 = 0 Then
Exit Sub
End If

' Find the record that matches the control.
Set rs = Me.Recordset.Clone
rs.FindFirst "[Item] = '" & Me![Text6] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If rs.NoMatch Then
If MsgBox(MsgA, StyleA, TitleA) = vbOKOnly Then
'this is where I'm stuck. how do I get the focus sent
'back to text6? everything I try still ends up with the
'cursor going to the next control. this code finds the
'inventory item as long as there is a match. I know
'the solution is probably simple, but then again, I'm
'teaching myself how to work with access.
End If
End If

End Sub
 

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