473,396 Members | 1,827 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,396 software developers and data experts.

Search Datasheet form

67
Hi everyone

I have been asked to create a search form for our shop that searches a form in datasheet view.

I have a Form called frmItems which has a subform called frmItems_Sub which has a textbox called Item in it which displays in datasheet view. frmItems has a button called btnSearch which opens a Form in popup view. When the user has entered the search criteria and clicks on the search button it should go to the record in the Forms!frmItems!frmItems_Sub!Item and highlight it.

Hope this makes sense

Regards
Wayne
Apr 23 '09 #1
16 5392
NeoPa
32,556 Expert Mod 16PB
Can you tell us what the fields are in the recordset?

I'm not sure exactly how this would be done, but with proper info I suspect we could find a way (or other experts may know already and jump in of course).
Apr 23 '09 #2
Wayneyh
67
Hi NeoPa

The Recordset contains
ID - AutoNumber
CompanyName - Textbox
ItemCode - Textbox
Item - Textbox
QuantityInStock - Number
txtDelivered - Textbox
txtSale - Textbox

Hope this helps as i am stuck. I tried a few things with the DoCmd.GotoRecord but couldn't get it to work. Any ideas would be appreciated.
Apr 23 '09 #3
NeoPa
32,556 Expert Mod 16PB
Let me start by asking if you've tried using the DoCmd.FindRecord() method?

If not, then it's probably a simple case of playing around with that. If you have, then maybe I'll have to help you play around with it to find the settings you need. This will be a little more complicated of course.

Let me know where you're at.
Apr 23 '09 #4
Wayneyh
67
Yes i did try DoCmd.FindRecord but i think my code was totally wrong.

regards
Apr 23 '09 #5
NeoPa
32,556 Expert Mod 16PB
I think we probably need to see your code then Wayne.
Apr 23 '09 #6
Wayneyh
67
Here is the last code i tried

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click()
  2.  
  3. If Me.txtSearch = "" Or IsNull(Me.txtSearch) Then
  4.     MsgBox "You Must Enter Something To Search For !"
  5. ElseIf Forms!frmItems!frmItems_Sub!Item = Me.txtSearch Then
  6.     DoCmd.FindRecord ("Forms!frmItems!frmItems_Sub!Item = Me.txtSearch")
  7. End If
  8. End Sub
Apr 23 '09 #7
NeoPa
32,556 Expert Mod 16PB
While I'm looking at this I would just draw your attention to another post I made elsewhere. I think it may help you.
It is always a good idea to ensure that variable name checking is enabled, AND your code compiles (at least compilation has been attempted), before submitting a question.

This avoids asking questions which are much more easily resolved on your own PC than on a forum.

To ensure variable name checking is enabled for all new modules, go to - Tools / Options / Editor (from the VBA Editor window) and set Require Variable Declaration to True (checked). For existing modules, ensure that the Option lines at the very top include :
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
To compile your project, select (again from the VBA Editor window) Debug / Compile Project Name.

We ARE generally happy to help with compilation problems too (If you find an error reported and you can't resolve it, let us know), but we do expect members to have tried compiling before submitting a question. That way we have a better idea of the sort of problem we're looking at.
Your line #6 is where it should be happening, but it rather looks like there is not much understanding there (Not a problem. We can help with that).

Can you tell me is [btnSearch] a control on your main form or the subform?
Apr 23 '09 #8
NeoPa
32,556 Expert Mod 16PB
Basically, you need to make the form you need to search on, the current form, and the control the current control, then code similar to this would be needed. This is as far as I can take you with the currently available information.
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.FindRecord(FindWhat:='Something', _
  2.                       Search:=acSearchAll, _
  3.                       OnlyCurrentField:=acCurrent, _
  4.                       FindFirst:=True)
Apr 23 '09 #9
Wayneyh
67
Hi NeoPa

The btnSearch Is on the main form frmItems.
Apr 24 '09 #10
NeoPa
32,556 Expert Mod 16PB
In that case you would need to switch focus to the subform before setting the control focus to the control you're searching. See post #9 for what to do then.

PS. I don't think there's an easy way of highlighting an individual record on a datasheet (or continuous) form. Anything applied to controls or the detail part of the form, is applied to all instances across the board. Only by changing a bound value could you do something like this (It would mean a field in the record which existed purely to show the highlight on the form). If set, then conditional formatting could be used to draw attention. This is not a great idea practically, as it involves ensuring all the values are set as expected before opening the form, and ensures you cannot use it in any type of multi-user environment.
Apr 24 '09 #11
Wayneyh
67
Thanks for all your help NeoPa. I will mess about and see if i can get it to work.

Regards
Wayne
Apr 24 '09 #12
NeoPa
32,556 Expert Mod 16PB
8-)

Let us know how you get on.
Apr 24 '09 #13
Wayneyh
67
Hi NeoPa

I works with the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click()
  2. If IsNull(Forms![frmItems]![txtSearch]) Or Forms![frmItems]![txtSearch] = "" Then
  3.     MsgBox "You Have Not Typed Anything To Search For"
  4. Else
  5.     Forms!frmItems!frmItems_Sub.SetFocus
  6.     DoCmd.GoToControl ("Item")
  7.     DoCmd.FindRecord Me!txtSearch
  8. End If
  9. End Sub
  10.  
Apr 24 '09 #14
NeoPa
32,556 Expert Mod 16PB
Thanks for posting Wayne, and well done :)

May I suggest some minor changes that may help :
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click()
  2. With Me
  3.     If IsNull(.txtSearch) Then
  4.         MsgBox "You Have Not Typed Anything To Search For"
  5.     Else
  6.         With .frmItems_Sub
  7.             Call .SetFocus
  8.             Call DoCmd.GoToControl("Item")
  9.             'May be possible to replace with :
  10.             'Call .Item.SetFocus
  11.         End With
  12.         Call DoCmd.FindRecord(.txtSearch)
  13.     End If
  14. End With
  15. End Sub
PS. Using Call is simply a way of saying explicitly that any return value from the procedure (function or subroutine) is ignored. It means that the syntax using parentheses can be used consistently.
Apr 24 '09 #15
Wayneyh
67
Again, thankyou for all your help.

Kindest Regards
Wayne
Apr 24 '09 #16
NeoPa
32,556 Expert Mod 16PB
@lovelydan
It seems you've already worked out to post your question in its own thread Dan.

I will delete these two posts as they are thread hijacking. No warning this time. You seem to be fixing your problems without help. Further help, if required, can be found in your own thread.
Apr 28 '09 #17

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

Similar topics

3
by: Kent Eilers | last post by:
I want to follow naming conventions for my controls - i usually prefix combo boxes with "cbo". When a form is in datasheet view however i do not want the user to see the 'cbo' prefix in front of...
4
by: Jan | last post by:
I am having problems trying to print a report based on a form. This is a search form only, no data input. There is a query that the form looks at, but then there are numerous comboxes that you...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
2
by: misschristalee | last post by:
I'm having a brain blockage day.... Scenario: Search Form with 6 text boxes Query has same six fields Each has this IIF: IIf(IsNull(!!),"",!!) with each dictating the correct text box of...
1
by: George Kandaz | last post by:
Steve, I posted a question to your last post almost a week ago, but never heard from you again. Please read my last message, as follows. Thanks. ...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
5
by: sara | last post by:
I haven't been able to find this answer in previous posts; I have a form, with a subform that is displayed in datasheet view, and one field "Item Description" could be from very few to many...
0
by: Josh E | last post by:
Hi, There are two sections to the form that I am creating. In the top section, I have the fields that I want the users to be able to update. In the bottom section (subform), I have all the...
2
by: Alan Forsyth | last post by:
That rather long subject says it. In Access97 running on XP - I want to display a Maximized size Form01, then open a Restore size Datasheet View Form02 on top of the first Form. PopUp won't give...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.