473,408 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Searching Records using a text box instead of ctrl+f? Access 2010

I used to be able to do this in 2003... but it has been a while.

I want a text box at the top of the form that will allow the user to type in an asset# to search the database

I know this is the Me.RecordsetClone feature... but for the life of me - it cannot get it to work.... (I think the bold part is the problem... vba autohelp shows this is supposed to be in parens... but that didnt' work either - online i found it encapsulated in "" but i keep getting an error of
Syntax error (missing operator) in expression.

I have a text box at top of form called searching
I have another text box which is called txtAssetID
then the specific fields are on the form that are needed for this view... the searching text box is where I want the user to put the asset# they want to look up.

right now we are using the ctrl+f function to do a search on the active field... but it looks rudamentary...

here is the code i have... any tweaks would be most appreciated!



Expand|Select|Wrap|Line Numbers
  1. Private Sub txtGoTo_AfterUpdate()
  2.     If (txtGoTo & vbNullString) = vbNullString Then Exit Sub
  3.     Dim rs As DAO.Recordset
  4.     Set rs = Me.RecordsetClone
  5.    rs.FindFirst "[Asset ID]" & "txtAssetID"    
  6.     If rs.NoMatch Then
  7.         MsgBox "Sorry, no such record '" & txtGoTo & "' was found.", _
  8.                vbOKOnly + vbInformation
  9.     Else
  10.         Me.Recordset.Bookmark = rs.Bookmark
  11.     End If
  12.     rs.Close
  13.     txtGoTo = Null
  14.  
  15. End Sub
Apr 5 '12 #1
12 6603
Rabbit
12,516 Expert Mod 8TB
1) I think you want the Asset ID to actually equal something so you need to put in equal.
2) txtAssetID is probably a variable or control on the form. If it's surrounded by quotes, then that makes it a string, it won't access the value of the variable/control.
3) If Asset ID is a string, you will need to surround the value it is matching to it in quotes.
Expand|Select|Wrap|Line Numbers
  1. "[Asset ID]=" & txtAssetID
Apr 5 '12 #2
Asset ID is the field name in the table that is already populated.

txtAssetID is the contorl on the form for Asset ID.

I have changed the field name to AssetID just to see if the space was the issue... and still am unable to use the textbox as the search.

Another thing I need to be able to do is update the record found... i keep seeing things that imply that the recordset is not updateable...am i trying the wrong thing all together? I just don't want to have the user use the popup find feature...
Apr 5 '12 #3
Rabbit
12,516 Expert Mod 8TB
You haven't shown the change you made. That is something I need to see because from what you've said, it sounds like you didn't fix any of the issues I brought up in my post.

If the recordset is not updateable, that's a different question and should be asked in a different thread.
Apr 5 '12 #4
sorry - am still trying to make it work... here is what I have currently. The records need to be updateable - after they are found.


Expand|Select|Wrap|Line Numbers
  1. Private Sub txtGoTo_AfterUpdate()
  2.     If (txtGoTo & vbNullString) = vbNullString Then Exit Sub
  3.     Dim rs As DAO.Recordset
  4.     Dim searchAsset As String
  5.  
  6.     Set rs = Me.RecordsetClone
  7.     searchAsset = Me!txtGoTo
  8.     rs.FindFirst "txtAssetID=" & searchAsset
  9.  
  10.  
  11.  
  12.     If rs.NoMatch Then
  13.         MsgBox "Sorry, no such record '" & txtGoTo & "' was found.", _
  14.                vbOKOnly + vbInformation
  15.     Else
  16.         Me.Recordset.Bookmark = rs.Bookmark
  17.     End If
  18.     rs.Close
  19.     txtGoTo = Null
  20.  
  21. End Sub
  22.  
  23.  
Apr 5 '12 #5
Rabbit
12,516 Expert Mod 8TB
That doesn't look like what I posted. Did you try that?
Apr 5 '12 #6
Ok put original code back in - changed the rs.findfirst line to your line - modified Asset ID to AssetID to match the table - and still not working get the following error:

Data Type mismatch in criteria expression

which when i debug points to that line.

Field in table is a text field so that it can handle both # & char's.



Expand|Select|Wrap|Line Numbers
  1. Private Sub txtGoTo_AfterUpdate()
  2.     If (txtGoTo & vbNullString) = vbNullString Then Exit Sub
  3.     Dim rs As DAO.Recordset
  4.     Set rs = Me.RecordsetClone
  5.    rs.FindFirst "[AssetID]=" & txtAssetID
  6.  
  7.  
  8.     If rs.NoMatch Then
  9.         MsgBox "Sorry, no such record '" & txtGoTo & "' was found.", _
  10.                vbOKOnly + vbInformation
  11.     Else
  12.         Me.Recordset.Bookmark = rs.Bookmark
  13.     End If
  14.     rs.Close
  15.     txtGoTo = Null
  16.  
  17. End Sub
  18.  
Apr 5 '12 #7
Rabbit
12,516 Expert Mod 8TB
Yes, that's point 3 in the post I made above.
3) If Asset ID is a string, you will need to surround the value it is matching to it in quotes.
You'll just need to account for it by surrounding the value it is matching in quotes.
Expand|Select|Wrap|Line Numbers
  1. "[Asset ID]='" & txtAssetID & "'"
Apr 5 '12 #8
sorry - i am not getting this for some reason - I am sure its simple... that is usually when I get lost lol....

You have now added a single quote into the "[Asset ID]" " and at the end in its own set of quotes - what is the single quote going to do - or what is it to represent?

[Asset ID] is now [AssetID] i changed it at the table level.
txtAssetID is the space on the form that displays the data for the current record.

txtGoTo is the name of the text box where i want the user to enter the asset # he is looking for, when he hits enter i want the database to display the contents of the record that has that asset #. It is currently unbound.

maybe I am not asking the question correctly....

i noticed if i take out the & sign though - at least it will look to run... though it cannot find a match even though I have copied it straight from the record and pasted it into the txtGoTo box...
Apr 5 '12 #9
Rabbit
12,516 Expert Mod 8TB
The quotes is to tell the SQL engine that what's inside the quotes is a string.
Expand|Select|Wrap|Line Numbers
  1. "[AssetID]='" & txtGoTo & "'"
If txtGoTo is ABC then the SQL engine will see this
Expand|Select|Wrap|Line Numbers
  1. [AssetID]='ABC'
Without the quotes, it sees this
Expand|Select|Wrap|Line Numbers
  1. [AssetID]=ABC
The quotes tell it that it's a string.
Apr 5 '12 #10
@Rabbit
Ah! I see the single quote is actually for the last half of the line... gotcha... trying that now.
Apr 5 '12 #11
well drat... that didn't work either - however i did get a combo box to do the same thing i was looking for - just has the drop down list if you click the arrow - i think i can live with that solution. Appreciate your help though!
Apr 5 '12 #12
Rabbit
12,516 Expert Mod 8TB
If a drop down list of the AssetID's work, that probably means that what was being typed into the textbox wasn't matching up exactly with what is in the table.
Apr 5 '12 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: PeteCresswell | last post by:
This is pursuant to another thread I tried to start, but can't find on my server. I've got to store rolling rates of return for investment funds - calendar year, quarterly, and monthly To cut...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
3
by: dlowry | last post by:
I'm currently using access 97. I'm relatively new to all this, so have attempted to create a company Asset Register when i've come across a problem im unsure of. I'm trying to create some sort of...
4
by: PerumalSamy | last post by:
Hi, i am doing program in asp.net using vb coding and MS Access as back end. i am having a table with date field and manipulation is based on the same. i am inserting value from textbox...
14
by: gilsygirl | last post by:
Hello everyone Am using a For Loop to access records from my database but the code opens instead of a specific record base on values passed by the user. These values a fields in the database...
2
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been...
0
by: erniemack | last post by:
Using comdlg32.dll to allow the user to reference a .jpg or .bmp file I want to have the default search to be the current folder plus \images. How can I pass that info to comdlg32.dll?
2
by: dougancil | last post by:
I have a user who had deleted some records from a database today using Access 2010. They have an ID field that's autonumbered. They have No Duplicates allowed. When they created a new record today,...
5
by: colsoft | last post by:
I am using Access 2010. Am generating reports for the records, one record per page. The records on the even pages have a light black background shading which appears when am printing. Please i need...
2
by: Bill Boord | last post by:
I need to be able to shut off the AutoCorrect "feature" within Access 2010 code. I have utilized Application.SetOption with method strings for other startup requirements, but I cannot seem to find a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.