Moving control to a Record and Input Mask Issue

G

Guest

I have two issues in my form.

1. I have the user enter a name to an input field above the main display
which displays about 20 records on the screen. Using a clone, a search is
done and if the record is found, an arrow points to the record on the main
display. However, the control is still in the input field, and the user has
to click the mouse on that record with the arrow to edit it. Can control be
automatically moved to the record. I saved the Current record to the
variable lngRecordNbr, can I send focus to that section of the screen ?

Set rsClone = Me.RecordsetClone
rsClone.FindFirst "[Lname]=" & "'" & Me.EmpSearch & "'"
Me.Bookmark = rsClone.Bookmark
lngRecordNbr = Me.CurrentRecord

2. I used an input mask of 00000 for numeric input and it always moves to
the far right as if the user already entered blank data. I tryed clicking on
the icon to justify left but it did not work.
 
A

Allen Browne

The line:
Me.Bookmark = rsClone.Bookmark
should make the found record current.

However, several things can go wrong with the code as it stands:

1. The code does not test if there is anything in the box after the user
finished typing and backspacing there. Test for Null.

2. The current record needs to be saved before you can move. The save could
fail, which leads to some weird errors. Explicitly save first.

3. After the FindFirst, you did not test to see if the name was actually
found. Explicitly test for NoMatch.

Try something like this:

Private Sub EmpSearch_AfterUpdate
Dim rs As DAO.Recordset
Dim strWhere As String

If Not IsNull(Me.EmpSearch) Then
If Me.Dirty Then 'Save first
Me.Dirty = False
End If

strWhere = "Lname = """ & Me.EmpSearch & """"
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
'Make the found record the current one in the form.
Me.Bookmark = rs.Bookmark
'Clear the search box if found?
Me.EmpSearch = Null
End If
End If

Set rs = Nothing
End Sub
 
G

Guest

Thank you for the input. I am finding the record and the arrow moves to
point to it as a black triangle pointing to the right. Is there a way to
have the mouse be positioned on the first field on that line ? I place the
code as you suggested, but the mouse remains positioned on the field the data
was entered.

Enter Last Name or Partial Last Name: Adams (The cursor remains here)

Last Name Branch
Smith Boston
Jones Atlanta
Adams Philadelphia (Instead of here)



Allen Browne said:
The line:
Me.Bookmark = rsClone.Bookmark
should make the found record current.

However, several things can go wrong with the code as it stands:

1. The code does not test if there is anything in the box after the user
finished typing and backspacing there. Test for Null.

2. The current record needs to be saved before you can move. The save could
fail, which leads to some weird errors. Explicitly save first.

3. After the FindFirst, you did not test to see if the name was actually
found. Explicitly test for NoMatch.

Try something like this:

Private Sub EmpSearch_AfterUpdate
Dim rs As DAO.Recordset
Dim strWhere As String

If Not IsNull(Me.EmpSearch) Then
If Me.Dirty Then 'Save first
Me.Dirty = False
End If

strWhere = "Lname = """ & Me.EmpSearch & """"
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
'Make the found record the current one in the form.
Me.Bookmark = rs.Bookmark
'Clear the search box if found?
Me.EmpSearch = Null
End If
End If

Set rs = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rmcompute said:
I have two issues in my form.

1. I have the user enter a name to an input field above the main display
which displays about 20 records on the screen. Using a clone, a search is
done and if the record is found, an arrow points to the record on the main
display. However, the control is still in the input field, and the user
has
to click the mouse on that record with the arrow to edit it. Can control
be
automatically moved to the record. I saved the Current record to the
variable lngRecordNbr, can I send focus to that section of the screen ?

Set rsClone = Me.RecordsetClone
rsClone.FindFirst "[Lname]=" & "'" & Me.EmpSearch & "'"
Me.Bookmark = rsClone.Bookmark
lngRecordNbr = Me.CurrentRecord

2. I used an input mask of 00000 for numeric input and it always moves to
the far right as if the user already entered blank data. I tryed clicking
on
the icon to justify left but it did not work.
 
A

Allen Browne

At the end of the procedure, add this line:
Me.[Field1].SetFocus
replacing Field1 with the name of the first field in your form.

Regarding your other question, I find that input masks do nothing useful,
and only slow down the data entry operator. Another example is that if a
digit is missed, you cannot just insert the digit: you have to type the
number again. They are about as helpful as 40-pound running shoes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rmcompute said:
Thank you for the input. I am finding the record and the arrow moves to
point to it as a black triangle pointing to the right. Is there a way to
have the mouse be positioned on the first field on that line ? I place
the
code as you suggested, but the mouse remains positioned on the field the
data
was entered.

Enter Last Name or Partial Last Name: Adams (The cursor remains here)

Last Name Branch
Smith Boston
Jones Atlanta
Adams Philadelphia (Instead of here)



Allen Browne said:
The line:
Me.Bookmark = rsClone.Bookmark
should make the found record current.

However, several things can go wrong with the code as it stands:

1. The code does not test if there is anything in the box after the user
finished typing and backspacing there. Test for Null.

2. The current record needs to be saved before you can move. The save
could
fail, which leads to some weird errors. Explicitly save first.

3. After the FindFirst, you did not test to see if the name was actually
found. Explicitly test for NoMatch.

Try something like this:

Private Sub EmpSearch_AfterUpdate
Dim rs As DAO.Recordset
Dim strWhere As String

If Not IsNull(Me.EmpSearch) Then
If Me.Dirty Then 'Save first
Me.Dirty = False
End If

strWhere = "Lname = """ & Me.EmpSearch & """"
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
'Make the found record the current one in the form.
Me.Bookmark = rs.Bookmark
'Clear the search box if found?
Me.EmpSearch = Null
End If
End If

Set rs = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rmcompute said:
I have two issues in my form.

1. I have the user enter a name to an input field above the main
display
which displays about 20 records on the screen. Using a clone, a search
is
done and if the record is found, an arrow points to the record on the
main
display. However, the control is still in the input field, and the
user
has
to click the mouse on that record with the arrow to edit it. Can
control
be
automatically moved to the record. I saved the Current record to the
variable lngRecordNbr, can I send focus to that section of the screen ?

Set rsClone = Me.RecordsetClone
rsClone.FindFirst "[Lname]=" & "'" & Me.EmpSearch & "'"
Me.Bookmark = rsClone.Bookmark
lngRecordNbr = Me.CurrentRecord

2. I used an input mask of 00000 for numeric input and it always moves
to
the far right as if the user already entered blank data. I tryed
clicking
on
the icon to justify left but it did not work.
 
G

Guest

Worked Perfectly.

Thank you, and thanks for the tip on input masks

Allen Browne said:
At the end of the procedure, add this line:
Me.[Field1].SetFocus
replacing Field1 with the name of the first field in your form.

Regarding your other question, I find that input masks do nothing useful,
and only slow down the data entry operator. Another example is that if a
digit is missed, you cannot just insert the digit: you have to type the
number again. They are about as helpful as 40-pound running shoes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rmcompute said:
Thank you for the input. I am finding the record and the arrow moves to
point to it as a black triangle pointing to the right. Is there a way to
have the mouse be positioned on the first field on that line ? I place
the
code as you suggested, but the mouse remains positioned on the field the
data
was entered.

Enter Last Name or Partial Last Name: Adams (The cursor remains here)

Last Name Branch
Smith Boston
Jones Atlanta
Adams Philadelphia (Instead of here)



Allen Browne said:
The line:
Me.Bookmark = rsClone.Bookmark
should make the found record current.

However, several things can go wrong with the code as it stands:

1. The code does not test if there is anything in the box after the user
finished typing and backspacing there. Test for Null.

2. The current record needs to be saved before you can move. The save
could
fail, which leads to some weird errors. Explicitly save first.

3. After the FindFirst, you did not test to see if the name was actually
found. Explicitly test for NoMatch.

Try something like this:

Private Sub EmpSearch_AfterUpdate
Dim rs As DAO.Recordset
Dim strWhere As String

If Not IsNull(Me.EmpSearch) Then
If Me.Dirty Then 'Save first
Me.Dirty = False
End If

strWhere = "Lname = """ & Me.EmpSearch & """"
Set rs = Me.RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
'Make the found record the current one in the form.
Me.Bookmark = rs.Bookmark
'Clear the search box if found?
Me.EmpSearch = Null
End If
End If

Set rs = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I have two issues in my form.

1. I have the user enter a name to an input field above the main
display
which displays about 20 records on the screen. Using a clone, a search
is
done and if the record is found, an arrow points to the record on the
main
display. However, the control is still in the input field, and the
user
has
to click the mouse on that record with the arrow to edit it. Can
control
be
automatically moved to the record. I saved the Current record to the
variable lngRecordNbr, can I send focus to that section of the screen ?

Set rsClone = Me.RecordsetClone
rsClone.FindFirst "[Lname]=" & "'" & Me.EmpSearch & "'"
Me.Bookmark = rsClone.Bookmark
lngRecordNbr = Me.CurrentRecord

2. I used an input mask of 00000 for numeric input and it always moves
to
the far right as if the user already entered blank data. I tryed
clicking
on
the icon to justify left but it did not work.
 

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