A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

text box lookup to list box



 
 
Thread Tools Display Modes
  #1  
Old August 29th, 2009, 06:28 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J
  #2  
Old August 29th, 2009, 07:05 PM posted to microsoft.public.access.gettingstarted
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default text box lookup to list box

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #3  
Old August 29th, 2009, 07:22 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #4  
Old August 29th, 2009, 08:23 PM posted to microsoft.public.access.gettingstarted
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default text box lookup to list box

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #5  
Old August 29th, 2009, 08:26 PM posted to microsoft.public.access.gettingstarted
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default text box lookup to list box

ooops

should be

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[XXXX] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub

change XXXX to the name of the field in the table that hlds the reg number

sorry - should read the stuff I wright before pressing the enter button

ooops



--
Wayne
Manchester, England.



"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #6  
Old August 29th, 2009, 09:48 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

Thanks for helping Wayne
I set up the two forms and added this to the text boxes after update event
but it does not display the searched record in the list box/form 2 below
My field name is License Tag Number in the table and I renamed my text box
to SearchReg for ease.

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

They are bound.

--
Ray J


"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #7  
Old August 29th, 2009, 09:51 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

oh, I did use License_tag_number instead of ID but left the brackets

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[License_tag_number] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

--
Ray J


"Raymond" wrote:

Thanks for helping Wayne
I set up the two forms and added this to the text boxes after update event
but it does not display the searched record in the list box/form 2 below
My field name is License Tag Number in the table and I renamed my text box
to SearchReg for ease.

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

They are bound.

--
Ray J


"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #8  
Old August 30th, 2009, 08:55 AM posted to microsoft.public.access.gettingstarted
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default text box lookup to list box

Glad you got it working.

--
Wayne
Manchester, England.



"Raymond" wrote:

oh, I did use License_tag_number instead of ID but left the brackets

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[License_tag_number] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

--
Ray J


"Raymond" wrote:

Thanks for helping Wayne
I set up the two forms and added this to the text boxes after update event
but it does not display the searched record in the list box/form 2 below
My field name is License Tag Number in the table and I renamed my text box
to SearchReg for ease.

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

They are bound.

--
Ray J


"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #9  
Old August 30th, 2009, 02:46 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

Hi Wayne,
Sorry, that did not work, the 2nd form does not find the desired record.
I don't get any errors. My After code reads as follows..

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[License_tag_number] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

my forms are test1 & test2
Link child & master License Tag Number
data is a table.
Test1 is a text box search
and test2 is a listbox

Hope you see the error I really appreciate your help.


--
Ray J


"Wayne-I-M" wrote:

Glad you got it working.

--
Wayne
Manchester, England.



"Raymond" wrote:

oh, I did use License_tag_number instead of ID but left the brackets

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[License_tag_number] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

--
Ray J


"Raymond" wrote:

Thanks for helping Wayne
I set up the two forms and added this to the text boxes after update event
but it does not display the searched record in the list box/form 2 below
My field name is License Tag Number in the table and I renamed my text box
to SearchReg for ease.

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

They are bound.

--
Ray J


"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

  #10  
Old September 1st, 2009, 10:39 PM posted to microsoft.public.access.gettingstarted
Raymond[_8_]
external usenet poster
 
Posts: 24
Default text box lookup to list box

Wayne, I have managed to get this form working right yet, are you still
available for further guidance?

I tried using a combo box to get the record and added all the fields from
the table on the form, I have a DoCmd.Requery in the afterevent but the
fields are not from the record I selected from the combo box. This is a new
form from the one with two forms so i'm experimenting on which one I can get
to work.
Thanks again.

--
Ray J




"Wayne-I-M" wrote:

Glad you got it working.

--
Wayne
Manchester, England.



"Raymond" wrote:

oh, I did use License_tag_number instead of ID but left the brackets

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[License_tag_number] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

--
Ray J


"Raymond" wrote:

Thanks for helping Wayne
I set up the two forms and added this to the text boxes after update event
but it does not display the searched record in the list box/form 2 below
My field name is License Tag Number in the table and I renamed my text box
to SearchReg for ease.

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.License_Tag_Number.SetFocus
Me.txtSearchReg = ""
End Sub

They are bound.

--
Ray J


"Wayne-I-M" wrote:

Ok thats not too difficult.

You need 2 forms
frm1 - format singl form
This will be based on a table or query that holds the details of the cars

frm2 - format continous form
This will be based on the times that all cars entered the car park

Link the 2 forms on the reg number.

I assume that you have a table with
IDfield
RegNumber
plus other details of the car (this is what frm1 will be based on)

Add and inbound to frm1
Use something like this on the AfterUpdate of the text box (I assume the
text box is called txtSearchReg)

Private Sub txtSearchReg_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![txtSearchReg], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.RegNumberField.SetFocus
Me.txtSearchReg = ""
End Sub


Now this will do what you want - but ;-)
If you added a combo box insead of using a text box - rember that you can
just type the reg number into a combo just as simply as a text box you can
set the expend to yes - which users like plus you could add something like
this to the combo
The same code as above to find the record
Plus
This will inform the users if they type in the wrong reg number or (if the
number is correct but the reg is not in the database ) give the option to add
a new reg
I would suggest you use a combo - but up to you


Private Sub txtSeachReg_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
msg = "'The reg you typed in - " & NewData & "' is not on file." & vbCr & vbCr
msg = msg & "Do you want to add a new car reg to the file?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "OK then try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("ADDTableNameHere", dbOpenDynaset)
rs.AddNew
rs![ADDRegField] = NewData
rs.Update
Response = acDataErrAdded
End If
End sub

Plus there is lots of other useful stuff you can do
Of course you can also do these with a text box - but more with combos

Hope this helps a little

Top Tip - use a combo to search for a record not a text box ?



--
Wayne
Manchester, England.



"Raymond" wrote:

Hi Wayne, Thanks for your reply. History or use info
I have a table of vistors by license plate, where when etc...
Desire is to type a tag number into a text box and the list below will list
all the times that car came into the park. The user can then click the
specific time/record and generate a letter(my next step, sub form). I used
the combo box you suggested but knowing the users I dont think that will
work.

I have an unbound text box to type in the plate number and wanted to use a
search command button to click, desired results would show in the list box
below.

Thougts? Thanks a bunch from Florida
Cheers


--
Ray J


"Wayne-I-M" wrote:

Hi Raymond

You can do this quite simply with a little code on your form's text box
afterUpdate event. But, (as you say you are new to access) can I suggest
that you design a form that displays all the records that you may want to to
search and then use the wizard to create a Combo Box and set the options on
the wizard to
Find a record on my form.

If this is not suitable for your uses then post back as most people will be
able to give you some help with the code.

Hope this helps

--
Wayne
Manchester, England.



"Raymond" wrote:

newbi user, trying to enter text in a text box (on a form) to find a record
in the database and display the records in a list box below on the same form.
Can anyone help. Thanks
--
Ray J

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:03 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.