Search Field

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

Guest

Hello,

How can I create a search field without using the Combo box.

I want a field where the user can enter the Loan Number, which consist of 10
characters beginning with 0
Example
Loan_Number
0011111111
0022222222
0033333333

Once they enter the loan number and press enter the system will search for
the loan number and the return the rest of the information for that loan.
Similar to the search option using the combo box.

I know this is a VB command but I don't know VB.
 
It really doesn't matter whether or not it is a combo box, the code is the
same. It should go in the After Update event of the text box on your form
where you want to enter the loan number (BTW, forms do not have fields.
Fields are only in tables and queries. Forms have controls of various types.
One of which is a combo box and another is a text box. This is probably
what you are calling a field. <end of preaching>).

It goes like this:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Now, the text box you use to do your lookup should be in the Header section
of your form and it should be the only control in the header. The reason is
that there is no way to cancel an After Update event and the focus goes to
the next control in the current section regardless of whether you found a
match or not. Putting your lookup text box as the only control in the Header
means the focus will stay on the lookup text box until you move the cursor to
the Detail section.
 
Your a fine preacher. That's how some of us learn.

I will try the command. I'm not familiar with VB so I will be working on it
for a long time.

Klatuu said:
It really doesn't matter whether or not it is a combo box, the code is the
same. It should go in the After Update event of the text box on your form
where you want to enter the loan number (BTW, forms do not have fields.
Fields are only in tables and queries. Forms have controls of various types.
One of which is a combo box and another is a text box. This is probably
what you are calling a field. <end of preaching>).

It goes like this:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Now, the text box you use to do your lookup should be in the Header section
of your form and it should be the only control in the header. The reason is
that there is no way to cancel an After Update event and the focus goes to
the next control in the current section regardless of whether you found a
match or not. Putting your lookup text box as the only control in the Header
means the focus will stay on the lookup text box until you move the cursor to
the Detail section.

Jose Aleman said:
Hello,

How can I create a search field without using the Combo box.

I want a field where the user can enter the Loan Number, which consist of 10
characters beginning with 0
Example
Loan_Number
0011111111
0022222222
0033333333

Once they enter the loan number and press enter the system will search for
the loan number and the return the rest of the information for that loan.
Similar to the search option using the combo box.

I know this is a VB command but I don't know VB.
 
Good Luck, if you have additional questions on this, post back. If you do,
it helps to post the code you are having problems with and the error you are
getting, if any.

Jose Aleman said:
Your a fine preacher. That's how some of us learn.

I will try the command. I'm not familiar with VB so I will be working on it
for a long time.

Klatuu said:
It really doesn't matter whether or not it is a combo box, the code is the
same. It should go in the After Update event of the text box on your form
where you want to enter the loan number (BTW, forms do not have fields.
Fields are only in tables and queries. Forms have controls of various types.
One of which is a combo box and another is a text box. This is probably
what you are calling a field. <end of preaching>).

It goes like this:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Now, the text box you use to do your lookup should be in the Header section
of your form and it should be the only control in the header. The reason is
that there is no way to cancel an After Update event and the focus goes to
the next control in the current section regardless of whether you found a
match or not. Putting your lookup text box as the only control in the Header
means the focus will stay on the lookup text box until you move the cursor to
the Detail section.

Jose Aleman said:
Hello,

How can I create a search field without using the Combo box.

I want a field where the user can enter the Loan Number, which consist of 10
characters beginning with 0
Example
Loan_Number
0011111111
0022222222
0033333333

Once they enter the loan number and press enter the system will search for
the loan number and the return the rest of the information for that loan.
Similar to the search option using the combo box.

I know this is a VB command but I don't know VB.
 
OK

This is what i'm going todo.

1. Go to Tool Box and Choose Text Box and place it in the Form Header.
2. On the Text Box, go to Properties and on the Event tab choose After Update.
3. Click on the Build button and choose Code builder and type the following
code:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Did I do this right?
 
Hi Jose,
[MActivity] is the name of the field in your table & [cboMActivity] is the
name of your text or combobox on your form - you will need to change these
two to whatever the names are for you.

Also, an add on is to add this to the 'got focus' event of your look up
combobox or text box [cboMActivity]=""
(again, change [cboMActivity] to whatever yours is called), this will 'clear'
your look up box so that the person using it doesnt get 'confused' :) ie once
they have used the lookup and later move to another record using the nav
buttons etc - without this, their last lookup would stay in the text/combo
box and might create a little confusion when they are working on another
record
...just a thought!
HTH
Chris

Jose said:
OK

This is what i'm going todo.

1. Go to Tool Box and Choose Text Box and place it in the Form Header.
2. On the Text Box, go to Properties and on the Event tab choose After Update.
3. Click on the Build button and choose Code builder and type the following
code:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Did I do this right?
 
Hey thanks Chris.

The function works good. On the "Got Focus" property do I type the same
function or is it only the [cboMActivity]=""? I try both ways but the
numbers shows anyway.



Chris B via AccessMonster.com said:
Hi Jose,
[MActivity] is the name of the field in your table & [cboMActivity] is the
name of your text or combobox on your form - you will need to change these
two to whatever the names are for you.

Also, an add on is to add this to the 'got focus' event of your look up
combobox or text box [cboMActivity]=""
(again, change [cboMActivity] to whatever yours is called), this will 'clear'
your look up box so that the person using it doesnt get 'confused' :) ie once
they have used the lookup and later move to another record using the nav
buttons etc - without this, their last lookup would stay in the text/combo
box and might create a little confusion when they are working on another
record
...just a thought!
HTH
Chris

Jose said:
OK

This is what i'm going todo.

1. Go to Tool Box and Choose Text Box and place it in the Form Header.
2. On the Text Box, go to Properties and on the Event tab choose After Update.
3. Click on the Build button and choose Code builder and type the following
code:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone
rst.FindFirst "[MActivity] = '" & Me.cboMActivity & "'"
If rst.NoMatch Then
MsgBox "No Matching Record Found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

Did I do this right?
 
Back
Top