473,549 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

searching a specific record

16 New Member
Hello everyone. I have been working on this DB for quite some time and still can't figure out a way to do what I want to do. It's a database that keep track of drawings and engineering change etc. Aslo, the tables for drawings are grouped by year.

I have a Main Form and on that main form, several cmd buttons to initialize sub forms are located. There are a quite a few tables and the names are quite simple. For example, for drawing that are produced in 2008 are called "2008 Drawing" and so on.

So on the main form, when I click on "Search Drawing" button, it assumes that the user is searching for the drawing in the current year which is 2008. Therefore, it brings up the form I created for "2008 Drawing". On this form, there are a lot of data related to the drawing: Drawing Number, Title, Draft Person, Year, etc.

Also, there are two CMD buttons called "Exit" which exits the current form and go back to the Main Form and "Search" which queries the data.

What I want to be able to do is to prompt the user to enter the "Drawing Number" which is bound to "Drawing Number" column of the "2008 Drawing" table. When I press the "Search" button, I want it to get the "Drawing Number" that users entered and query the query I created base on table "2008 Drawing". When the query is done, I want to populate the data back in the form "2008 Drawing". There will be only one record because all the drawing numbers are unique.

This is what I did and did not work unfortunately.

------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3. ' Move crusor to Drawing number
  4. DrawingNumber.SetFocus
  5.  
  6. ‘ Will it be like this to prompt user to enter drawing number?
  7. Forms![2008 Drawing].[Drawing Number] = [Drawing Number:]  
  8.  
  9. End Sub
  10.  
  11. ----------------------------------------------
  12. Public Sub cmdSearch_Click()
  13.  
  14. ' SQL variable
  15. Dim mySQL As String
  16.  
  17. ' Select everything from 2008 Elec table and query the drawing number user provided
  18.  
  19. mySQL = "SELECT * FROM [2008 Drawing]"
  20.  
  21. DoCmd.RunSQL mySQL 
  22.  
  23. End Sub
  24. ---------------------------------------------
  25. But then, I realize that RunSQL can't run "SELECT" statement. 
  26.  
  27. I need to get the "Drawing Number" from user before I press "Search" button. That's why I was thinking of prompting user to enter the "Drawing Number" in "Form_current". 
  28.  
  29. Anyway, I changed code to the following because RunSQL can't do "SELECT":
  30.  
  31. -------------------------------------------------
  32. Public Sub cmdSearch_Click()
  33.  
  34. ' SQL variable
  35. Dim mySQL As String
  36. Dim con As Object
  37. Dim recSet As Object
  38.  
  39. Set con = Application.CurrentProject.Connection
  40.  
  41. ' Select everything from 2008 Elec table
  42. mySQL = "SELECT * FROM [2008 Drawing]"
  43. ' Drawing Number is provided by user
  44. Set recSet = CreateObject("ADODB.Recordset")
  45. recSet.Open mySQL, con, adOpenStatic, adLockOptimistic, adCmdTable
  46.  
  47. End Sub
--------------------------------------------------
But the recSet.Open is giving me error.

All I want to be able to do is to be able to search one record at a time from the user input by pressing "Search" button. I also want to be able to switch between the forms by just choosing the "year drop down" list from the form. Say, if I choose "2007", it should close the form "2008 Drawing" and open up the "2007 Drawing" form and should automatically know to query the "2007 Drawing" table/query.

Any suggestion at all is really welcome.

Thanks.
Aug 20 '08 #1
20 2509
tkip
16 New Member
My bad. I just realized that I gave the wrong information. The "Year" field is unbound and it is not a "drop down" list. It's just a field to enter int.
Aug 20 '08 #2
NeoPa
32,564 Recognized Expert Moderator MVP
A couple of ideas :
  1. Don't store your data in separate tables for years. Simply have a [Year] field in the single table to separate out the different years. This will make the design of your database far less complicated.
  2. Let us know which line number the code fails on and the details of the error.
Aug 20 '08 #3
tkip
16 New Member
I added a few codes to make "Year" field works. It's ture that if I have year as a column in the table, it will make it simpler. I just don't want to start creating everything from ground up. My boos gave me the MS Access DB they have been using since 1999 which doesn't have any sort of form. The only way for them to seperate each drawing is by spearating "Type of Drawing" and "Year". There are a lot of tables. They way they separate is sort of simple. If the drawing or schematic is "Electrical Drawing" and the year is "2008", they call the table "2008 Electrical Drawing". If it is mechanical, they name it in the same way. So that's a lot of tables and way too many records and stuff to play with.

What I did was that I created a field call "Year" and open up the query according to the year entered.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Year_AfterUpdate()
  2.  
  3. ' If user changes the year, check the last 2 digits
  4.  
  5. ' If it is '08
  6. If Right(Me.intYear, 2) = "08" Then
  7.  
  8. ' Close Current Form
  9. DoCmd.Close acForm, Me.Name, acSaveNo
  10.  
  11. 'Open 2008 Form
  12. DoCmd.OpenForm "Electrical 2008", acNormal
  13.  
  14. ' If it is '07
  15. ElseIf Right(Me.intYear, 2) = "07" Then
  16.  
  17. ' Close Current Form
  18. DoCmd.Close acForm, Me.Name, acSaveNo
  19.  
  20. 'Open 2007 Form
  21. DoCmd.OpenForm "Electrical 2007", acNormal
  22.  
  23. ' If it is '06
  24. ElseIf Right(Me.intYear, 2) = "06" Then
  25.  
  26. ' Close Current Form
  27. DoCmd.Close acForm, Me.Name, acSaveNo
  28.  
  29. 'Open 2006 Form
  30. DoCmd.OpenForm "Electrical 2006", acNormal
  31. .
  32. .
  33. .
  34. etc
------------------------

What line am I having problem with?

Then, it's line "21" and "45"

Also, keep in mind that I am just guessing some of those codes and I still don't have a clue how to pass the user input data which in this case "Drawing Number" and then use that data to query the database. I then want the result to display (populate) on the form.
Aug 20 '08 #4
NeoPa
32,564 Recognized Expert Moderator MVP
Right then.

I get that you are not in a position to redesign the database at this time. That's actually quite a common reason for having shoddy data structures (a perfectly good and practical reason of course).

Having said that, your question is quite involved and rather calls for me to get deeply involved in your project. This I like to avoid if possible. I don't see my role to diagnose and fix your overall problem.

If you can break your problems down into individual questions I can help with, then fine. Remotely diagnosing a database I can't see takes too much much time (generally many hours). The purpose of this site is mainly for you to post your questions after you've broken them down into fundamental issues.
Also, keep in mind that I am just guessing some of those codes and I still don't have a clue how to pass the user input data which in this case "Drawing Number" and then use that data to query the database. I then want the result to display (populate) on the form.
For instance, if you could explain what you mean by this I could probably help you. Unfortunately there are many interpretations of "how to pass the user input data". Remember that most of what you say is dependent on the context, and I don't have that so it needs to be much clearer than when explaining face to face.
Aug 20 '08 #5
tkip
16 New Member
Ok.

Forget about the multiple tables and stuff that I mentioned above.

Assume that the following is my current DB:

1) I have a table called "Electrical 2008"
(a) it has these fields in the table
Drawing Number, Title, Job Number, Resource, Project Number

2) I created a query based on the above table and it is called "Elec 2008 Query"

3) I also created a form called "Elec Form" with multiple text fields that includes all the field names from the table "Electrical 2008"
(a) The form has a button called "Search" that is supposed to query either the table or the query

(b)The control source for the text fields are bound to the table "Electrical 2008".

What I am trying to accomplish is to search a record from the form associated to the unique "Drawing Number".

So user will type in the "Drawing Number" in the form - which I set up as a "text" field. I know it should be "int" or "long". But the drawing numbers starts with "0" eg. 012345. If I set the field as "int", it omits the leading "Zero" and I can't let that happen. It's the naming procedure of the dept.

After the user keyed in the "Drawing Number" in the "Search Form", he/she will click on the "Search" button. Then everything associated with that unique "Drawing Number" should "populate" in the same form.

I don't know if it makes sense to you.

a) user enters the "Drawing Number" in the text fied in the form called "Elec Form"
b) Then cliks on the "Search" button
c) Everything related/associated/connected/tied to/linked to the "Drawing Number" user entered populate/display/show on the current form. It basically fills all the other text fields in the form other than the "Drawing Number" because user already provided that data.

How do I go about doing that?

Thanks!
Aug 25 '08 #6
NeoPa
32,564 Recognized Expert Moderator MVP
Firstly, you're wrong to think a text field is wrong :D Actually it's 100% correct for that type of field. Having people designing systems where numbers as text (formatted to x positions) are used is where the problem lies. I'm afraid you're not in a unique position though ;)

Anyway, let me see if I have you clearly...
  • You want a form to fit a table ([Electrical 2008] probably or query [Elec 2008 Query] if necessary).
  • There will be five TextBox controls on the form to match the fields [Drawing Number], [Title], [Job Number], [Resource] & [Project Number].
  • When the operator enters any data into the [Drawing Number] control on the form, you want, instead of the current record being updated, for the form to display the matching record?
Aug 25 '08 #7
tkip
16 New Member
Yes. I do not want to update the record.

1) When user enter data into "Drawing Number"
2) Display the mathcing record in the same form

So we are finally on the same page.
Aug 26 '08 #8
NeoPa
32,564 Recognized Expert Moderator MVP
Right, in that case what I think you need is a simple form designed to edit a record from your [Electrical 2008] table.

For all controls other than [Drawing Number] have a BeforeUpdate() procedure that simply sets Cancel=True.

For [Drawing Number], have a BeforeUpdate() procedure that does that too, but in addition, it should set the Filter property of the form to reflect the entered value then call Me.ReQuery. This will have the effect of showing the selected record if a matching one exists.

Does this sound like it does what you need?
Aug 26 '08 #9
tkip
16 New Member
Yeah...kinda sound right expect that I don't know how to set filter so that the query takes the "Drawing Number" that user enters.

That is the thing I have been trying to resolve. Have a look at the code from my previous posts. You will see that I try implementing filter of some sort so that the "Drawaing Number" that the operator enters is set as the filter to either query the table or the query itself.

I realize that need to use Me.Requery to display the query result. But first thing first.

If I can't set the filter right, nothing is going to display properly on the form.

Can you give me an example if you dont' mind?
Aug 26 '08 #10

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

Similar topics

0
1221
by: Benny Eckert | last post by:
Hi everybody, Me and my colleague use the same DB under win98 Access 2000. He recently upgraded to win2K, same access version. When I search a specific record in a form using a "search record" button, everything works. When he tries to do the same, the specific record can't be found. When whe copy the complete DB to his computer, it...
9
1560
by: Jack-of-all-traits | last post by:
I have certain words, or groups of words (4 or less) input in my fields in Access 2002 xp pro atmosphere. The data is essentially in the tables., so what I want to do is get access with the click of a button to take each and every string from a specific field and possibly each and every single record ---> and place them into the search...
1
1726
by: David | last post by:
Hello, I use the VS .NET 2003. Say I have a Windows form (with C# code, of course) which is connected to a database to one table. I can browse through the records, but I don't know how to accomplish a search for a specific record. I would like to have a button that by clicking it, a response window will be opened. Say that the search will be...
0
1210
by: fig000 | last post by:
Hi, I'm trying to use the sqldatasource control and a detailsview to create a fully functional data entry screen; it's quite easy. I can see the strength of creating a master grid associated with a detailsview that gives you access to the record you choose in the grid. However one of the basic functions of this type of screen is the...
0
1198
by: Roald van Geleuken | last post by:
Been trying a few things but not been able to solve this so far. I have 3 tables: - source data shown in a paged gridview - processed data (1 or more records per source record) shown in paged detailview - additonal messages ( 1 or more per processed data record) shown in another non-paged gridview Selecting a source record will show the...
11
3420
by: TheDataGuy | last post by:
Using MS ACCESS 2002 I developed a FORM, and within that FORM, I created and added a SEARCH BUTTON, and then I created a SUB-FORM, so that when an the END USER clicks on the FORM it will POP-UP the SUB-FORM, and in that SUB-FORM I added all the FIELDS of the information I wanted to view. The SUB-FORM was created to do the actual SEARCHING. ...
7
4531
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
4
5323
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for...
3
2154
by: Ahmad Jalil Qarshi | last post by:
Hi, I have a text file having size about 2 GB. The text file format is like: Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values For example consider following chunk of actual data:
0
7726
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
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 we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.