473,480 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can Anybody help me to create "Find" Window in access

10 New Member
I need to create a process exactly like Access Find window which can search anything anywhere.

e.g. A form contains one or two sub forms which show some data. The user can select one of the fields on the sub forms and clicks a button. A new form opens and asks the search item. When the search item in entered , it should find the item in the sub form selected.
I did this with the search item on the same form and it works fine. BUT when it is done from other form then I have an error. I used FindRecord method.
Any help is appreciated.
Feb 26 '14 #1
18 1805
NeoPa
32,556 Recognized Expert Moderator MVP
Let's start by asking you to post the code you have already tried with an explanation of what went wrong and where.

If you already have it working on the main form then getting it to work on the subforms should be a simple matter of adjusting your references. See Referring to Items on a Sub-Form for more on that aspect.
Mar 1 '14 #2
zareh
10 New Member
Actually I made some progress since I posted this question here.

BUT not 100%.

The codes are little bit long, NOT actually long but in many places.

My main problem is to refer to the
* main form
* sub form
* and field name which had the focus

BY variable name. Because this search must work for every form the user opens. When these items are known then I have to use the followings:
Expand|Select|Wrap|Line Numbers
  1. Dim a As Control
  2. Dim b As Form
  3. Set a = Screen.PreviousControl
  4. Set b = Screen.ActiveForm
  5. e = a.Name     'last control name
  6. d = b.Name     ' last form name
  7.  
  8. Forms(d).Controls(e).SetFocus ''''''''here is the problem
  9.  
  10. Searchitem = Text0
  11.  
  12. DoCmd.FindRecord Searchitem, acStart, False, acSearchAll, False, acCurrent, True
Now my problem is where I marked above.
Sometimes "e" becomes the sub form's name and sometimes it becomes the field's name (in the sub form).

Any help?
Can we attache a file here?
Thanks
Mar 2 '14 #3
NeoPa
32,556 Recognized Expert Moderator MVP
That's the code and where the problem occurred - but not what went wrong.
Mar 3 '14 #4
zareh
10 New Member
Thanks for the reply.
On the main form I have a command button which opens the search form. In the search form I have a text box which is for the search item input and two command buttons. One is for "Find First" and the other is for "Find Next". When search item is entered and "Find First" is clicked, fist occurrences of the search item is found without problem, but when Find Next is clicked, an error msg appears :
Run-time error '2162':
A macro set to one of the current fields properties failed because of an error in a FindRecord action argument.

The interesting thing is : when I press Debug on this error msg box, program stops and when I press F5 it finds the search item (next one) without any error.??????!!!!!

It's making me crazy !!!!!!!!!!!!

Any help would be appreciated.
Mar 3 '14 #5
NeoPa
32,556 Recognized Expert Moderator MVP
The code you posted doesn't match your explanation. If the code that fails is for the FindNext button then we need to see that code - with the procedure wrappers (Private Sub ... End Sub).

If it's a macro instead, then we're not communicating very well. Frankly, macros (non-VBA code) is not something I'm interested in helping with as I have little experience of them and never recommend using them. Also, trying to communicate what's going on with macros is too difficult to be reliable and we just waste loads of time and effort.

All in all, if it's macros rather than VBA then I'm not able/willing to help. If it's VBA code then please post what you're actually having problems with.
Mar 4 '14 #6
zareh
10 New Member
Thanks for the reply.

This is not a macro.

In the Find Next button I have :

Expand|Select|Wrap|Line Numbers
  1. Forms(d).Controls(e).SetFocus
  2.  
  3. searchitem = Text0
  4.  
  5. DoCmd.FindRecord searchitem, acStart, False, acSearchAll, False, acCurrent, False
  6.  
This part makes me really mad : (I said before)
when I press Debug on this error msg box, program stops and when I press F5 it finds the search item (next one) without any error.??????!!!!!Every time ???!!!!

Thanks again.
Mar 4 '14 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Please reread my last post carefully. Particularly in relation to what we need you to post in order to continue.
Mar 4 '14 #8
zareh
10 New Member
Thanks a lot, Here is the complete codes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'This is on the click event of a command button on the main form which opens the search form.
  3.  
  4. Private Sub Command3_Click()
  5. Dim a As Control
  6. Dim b As Form
  7. Set a = Screen.PreviousControl
  8. Set b = Screen.ActiveForm
  9. e = a.Name           'last control name
  10. d = b.Name           ' last form name
  11. On Error GoTo Err_Command3_Click
  12.     Dim stDocName As String
  13.     Dim stLinkCriteria As String
  14.     stDocName = "Search"
  15.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  16.  
  17. Exit_Command3_Click:
  18.     Exit Sub
  19.  
  20. Err_Command3_Click:
  21.     MsgBox Err.Description
  22.     Resume Exit_Command3_Click
  23.  
  24. End Sub
  25.  
  26.  
  27. 'This is on the click event of the "Find First" button on the Search form.
  28. Private Sub FindFirst_Click()
  29. Forms(d).Controls(e).SetFocus
  30. searchitem = Text0
  31. DoCmd.FindRecord searchitem, acStart, False, acSearchAll, False, acCurrent, True
  32. End Sub
  33.  
  34. 'This is on the click event of the "Find Next" button on the Search form.
  35. Private Sub FindNext_Click()
  36. Forms(d).Controls(e).SetFocus
  37. searchitem = Text0
  38. DoCmd.FindRecord searchitem, acStart, False, acSearchAll, False, acCurrent, False
  39. End Sub
  40. '''''''''''''''''''
  41.  
  42. 'Also I have a module which declares the Global variables "a,b,d,e"
  43.  
Mar 5 '14 #9
NeoPa
32,556 Recognized Expert Moderator MVP
Am I confused?

You were asking about what happens when the find next button is clicked. This code is for opening the search form. How can this code allow us to continue?
Mar 5 '14 #10
zareh
10 New Member
Command3_click opens the Search form.

At the bottom of the codes you can see another sub which is for FindNext button. Private Sub FindNext_Click()
Mar 6 '14 #11
NeoPa
32,556 Recognized Expert Moderator MVP
Clearly I was confused! Apologies for that.

Your code for FindNext uses FindRecord(). This should also work, but I suspect setting the Search parameter to acSearchAll is possibly overriding the FindFirst parameter (False).

So try these remedies :
  1. Use DoCmd.FindNext() instead.
  2. Use acDown for the Search parameter.
Mar 6 '14 #12
zareh
10 New Member
Thanks a lot.

I tried but the result is the same.
Mar 6 '14 #13
NeoPa
32,556 Recognized Expert Moderator MVP
Really? You tried FindNext() and it did what? Kept finding the first occurrence?
Mar 6 '14 #14
zareh
10 New Member
FindNext() does not work at all. It does NOTHING, no finding no error.

May be the parameters are not correct. I used exactly :

DoCmd.FindNext()
Mar 7 '14 #15
NeoPa
32,556 Recognized Expert Moderator MVP
You need to pass relevant parameters if you want it to do anything.
Mar 7 '14 #16
zareh
10 New Member
In the FindNext there is no parameter to pass. I looked at the VB help.
'''''''''''''''''''''''

FindNext Method
See AlsoApplies ToExampleSpecificsThe FindNext method carries out the FindNext action in Visual Basic.

expression.FindNext
expression Required. An expression that returns a DoCmd object.

Remarks
This method has no arguments and can be called using the syntax DoCmd.FindNext.

You can use the FindNext method to find the next record that meets the criteria specified by the previous FindRecord method or the Find In Field dialog box, available by clicking Find on the Edit menu. You can use the FindNext method to search repeatedly for records. For example, you can move successively through all the records for a specific customer.

''''''''''''''''''''''''''
Mar 8 '14 #17
NeoPa
32,556 Recognized Expert Moderator MVP
I beg your pardon. My mistake. Very strange, as I thought I'd checked it out myself earlier. Now I can't remember what it was I saw but as you say, it clearly wasn't that.

Frankly, I believe using unspecified DoCmd commands is a poor approach. It requires that the correct object is active in order for it to work as expected. They are available to support macro programming, which is kludgy at best. A more reliable approach would be to use DAO recordsets and do the searching either on the form's .Recordset or .RecordsetClone objects. If you use .RecordsetClone for the searching you need to follow that with setting the current record on the form itself by setting the .Recordset.Bookmark to the .RecordsetClone.Bookmark.
Mar 9 '14 #18
zareh
10 New Member
OK thanks a lot.
Appreciate your time.
Mar 10 '14 #19

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

Similar topics

2
4964
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
10
7374
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
0
889
by: Goose14 | last post by:
I'm trying to create a window in a 3rd party application. What do I mean by window? Well what I want to create a simple "window" that is "overlayed" over a 3rd party application ie. Internet...
5
2066
by: robertaraj | last post by:
Hi All, I am new to vb.net, Can anybody tell how to create a pop up window at runtime. If I have more than 100 product names in the database, While I click the letter 'A' in text box, the...
7
1958
by: mukeshrasm | last post by:
hi I want to create login window like youtube.com means when user clicks on Login a small screen get opened so what type of screen it is and how can I create it.
3
1668
by: hanz | last post by:
Hello everyone, I am trying to create an MS Access file using Perl in a Linux environment. By the way I am on a SuSE Linux envrironment. I have already installed the DBI module. I am looking...
0
1341
by: =?Utf-8?B?QmFydE1hbg==?= | last post by:
Greetings, To begin with we have an archetecture which has a manager Asssembly which loads "Plug-in" assemblies using reflection, when a the UI prompts the manager. This loading of the...
0
707
by: farhanusm | last post by:
Dear member can anybody help me to tell how i can make validator window in ms access 2003 , i mean it's like a pop up window which come in to picture when i click the tab for my database field ,...
0
1113
by: John James | last post by:
I need to create a new Access DB based on one already existing...Hence, I am attempting to copy the db struture and not the data; It's a yearly db I need to track/create. I looked on this site and...
0
6911
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
7050
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
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
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
5344
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,...
1
4787
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...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.