473,461 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

To search record

145 100+
I want to create a search form for a library which contain 2 option group;1 is for searching according to keywords,exact match,first on field and phrase,another is type of searching which have different field table such as title,publication,subject,author,call number,ISBN, and any. and also a text field to enter searching.When the search button is click,the result will appear in another form line by line.Do i need to create a query?I dont know ho to create the coding,I get confuse.I am very new to this.
Jul 29 '08
162 9520
NeoPa
32,556 Expert Mod 16PB
(1) I already ur code, at first it seem to be running eventhough a message box appear
(2) However,the next time I try it,nothing happen when I click the Search button...what is the problem?Is it the code? I do not change anything except I change the name of the button (cmdSearch) and the text box(txtFind) to match the name in the code

I try to make a new form but it still doesnt work...Any detail that u want cuz im not sure what detail it is cuz there is no error message for (2)
I fixed the error but the code do not open the [Printing Media Library] form instead a Find and Replace box appear
What I suggest you do at this point, bearing in mind the other question relating to the code as well, is to post in (copy/paste please) the code you are actually using, then expain as simply and clearly as possible, what is going wrong AT THIS TIME (to match the code posted).

If you can include both of these in a single post I will have something I can refer to and work from in one place.
Sep 5 '08 #101
puT3
145 100+
This is the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.  
  3. Dim strWhere As String, strField As String
  4.  
  5. '%F ==> Field to search on
  6. '%E ==> Equality operator
  7. '%V ==> Value (to search for)
  8.  
  9. strWhere = "[%F] Like '%V'"
  10.  
  11. Select Case Me.[Search Type]
  12.  
  13.     Case 1
  14.         strField = "Title"
  15.     Case 2
  16.         strField = "Author Name"
  17.     Case 3
  18.         strField = "Publication Name"
  19.     Case 4
  20.         strField = "CallNumber"
  21.     Case 5
  22.         strField = "Topical Headings"
  23.     Case 6
  24.         strField = "ISBN/ISSN"
  25. End Select
  26.  
  27. strWhere = Replace(strWhere, "%F", strField)
  28.  
  29. Select Case Me.[Search By]
  30.  
  31.     Case 1
  32.         strWhere = Replace(strWhere, "%V", "*" & Me.txtFind & "*")
  33.     Case 2
  34.         strWhere = Replace(strWhere, "%V", Me.txtFind)
  35.         strWhere = Replace(strWhere, "Like", "=")
  36.     Case 3
  37.         strWhere = Replace(strWhere, "%V", Me.txtFind & "*")
  38. End Select
  39.  
  40. DoCmd.OpenForm "Printing Media Library", , , strWhere, acFormReadOnly
  41.  
  42. End Sub
  43.  
When I click the button,a Office Find and Replace box appear
Sep 6 '08 #102
NeoPa
32,556 Expert Mod 16PB
OK. Nothing obvious there.
  1. Does it happen this way for every Option you select, or are there some combinations that work ok?
  2. Please add the following line after line #38 of your posted code anyway. Whenever you report on this error after this you can include the results of this line with the report so I know what's been selected :
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print strWhere
Sep 6 '08 #103
NeoPa
32,556 Expert Mod 16PB
While you're about it, can you dump in the SQL of the query you have the form ([Printing Media Library]) bound to (and its name).

I will reformat it for you don't worry. Just dump it in.
Sep 6 '08 #104
puT3
145 100+
While you're about it, can you dump in the SQL of the query you have the form ([Printing Media Library]) bound to (and its name).

I will reformat it for you don't worry. Just dump it in.
Sorry,I dont understand do u mean to discard it, discard it from the RecordSource of the search form or just discard the SQL in the query?
Sep 8 '08 #105
puT3
145 100+
Another thing,why my button doesnt work even if I click it nothing happen...But before this it work
Sep 8 '08 #106
puT3
145 100+
My button still doesnt work...why is this happen?

It work fine before (the Find and Replace box appear when i click it)

When I try to click it today,it doesnt work,nothing happen...I already try but the result still the same
Sep 8 '08 #107
puT3
145 100+
Im sorry I cant give u any update today,cuz the button still has problem,nothing happen when i click it
Sep 8 '08 #108
Stewart Ross
2,545 Expert Mod 2GB
puT3, you will have to check the On Click event of your button yourself. Posting three times that your button no longer works is not going to help you or us in this very long thread - only you will be able to check why your button does not do what you expect it to do!!

We can assist you in many ways - but not with working out for you why your button no longer clicks as it did.

Also, please post in words not in phone text; many of our readers will not understand what you write if you use such abbreviations.

-Stewart
Sep 8 '08 #109
NeoPa
32,556 Expert Mod 16PB
While you're about it, can you dump in the SQL of the query you have the form ([Printing Media Library]) bound to (and its name).

I will reformat it for you don't worry. Just dump it in.
Sorry if I wasn't clear.

What I meant was to copy the SQL and post it in this thread. This will give me the opportunity to review the SQL you're ACTUALLY using at this point.
Sep 8 '08 #110
NeoPa
32,556 Expert Mod 16PB
Another thing,why my button doesnt work even if I click it nothing happen...But before this it work
There's no way I can know this.

Clearly you have made some change that I'm completely unaware of.

This is why I have tried so hard to impress upon you the importance of clear and accurate communication. Without it I can't help you.
Sep 8 '08 #111
tkip
16
You seems to have the similar problem that I had before I found a solution. All the suggestions you've received so far is very good.

This is my suggestion:

(1) Create a query based on your table ('Printing Table or whatever you call it")
(2) Create a form based on your query
(3) Edit the query
- Select the query you created and click on "View" from toolbar and select "SQL View"

Then edit the SQL as follow (make sure to change the variables to suite your need. This is just an example)

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![frmLibrary]![txtISBN] Long, [Forms]![frmLibrary]![txtAuthor] Long,[Forms]![frmLibrary]![txtTitle] Long;
  2. SELECT [Your Table Name Here].*
  3. FROM [Your Table Name]
  4. WHERE IIf(Forms![frmLibrary]!txtISBN="",(Not [Your Table Name].[ISBN]),True)
  5.  Or ([Your Table Name].[ISBN]=Forms![frmLibrary]!txtISBN) 
  6. And ((Forms![frmLibrary]!txtAuthor Is Null) 
  7. Or ([Your Table Name].Author Like "*" & Forms![frmLibrary]!txtAuthor & "*"))
  8. And ((Forms![frmLibrary]!txtTitle Is Null) 
  9. Or ([Your Table Name].Title Like "*" & Forms![frmLibrary]!txtTitle & "*"));
  10.  
  11.  
Save the SQL statements.

Then in the form you created, make some combo boxes and/or text box (whatever is appropriate for your need) in the form header. Just make sure that they are not bound to anything (unbound).

Then on the "Search" command code (VBA), add this:

Expand|Select|Wrap|Line Numbers
  1. Public cmdSearch_Click()
  2.   Dim strSQL As String                  'The criteria string set in Query
  3.     Dim lngLen As Long      
  4.  
  5. 'Use the value from text field and match it with ISBN column from your table
  6.     If Not IsNull(Me.txtISBN) Then
  7.         strSQL = strSQL & "([ISBN] = """ & Me.txtISBN & """) AND "
  8.     End If
  9.  
  10. 'Use key word "Like" to find text anywhere in the field.
  11.     If Not IsNull(Me.txtAuthor) Then
  12.         strSQL = strSQL & "([Author] Like ""*" & Me.txtAuthor & "*"") AND "
  13.     End If
  14.  
  15. 'Use key word "Like" to find text anywhere in the field.
  16.     If Not IsNull(Me.txtTitle) Then
  17.         strSQL = strSQL & "([Title] Like ""*" & Me.txtTitle & "*"") AND "
  18.     End If
  19.  
  20. 'See if the string has more than 5 characters (a trailng " AND ") to remove.
  21.     lngLen = Len(strSQL) - 5
  22.     If lngLen <= 0 Then     'Nah: there was nothing in the string.
  23.         MsgBox "No parameter(s). Please set parameter(s) and try again.", vbInformation, "No Parameter(s)!"
  24.     Else                    'Yep: there is something there, so remove the " AND " at the end.
  25.         strSQL = Left$(strSQL, lngLen)
  26.     'Print Debug Info to Immediate Window (Ctrl+G).
  27.         Debug.Print strSQL
  28.  
  29.     'Finally, apply the string as the form's Filter.
  30.         Me.Filter = strSQL
  31.         Me.FilterOn = True
  32.     End If
  33.  
The above will allow user to provide as many parameters as they wish to provide. You can search by key word or exact match for both the "Title" and "Author". If user type in "ISBN" number, it will return the matching record from the table in the current form. I think it is much simpler and cleaner to just display the results in the same form.

That's what I did for my database and it works just fine. I hope that helps.
Sep 8 '08 #112
puT3
145 100+
puT3, you will have to check the On Click event of your button yourself. Posting three times that your button no longer works is not going to help you or us in this very long thread - only you will be able to check why your button does not do what you expect it to do!!

We can assist you in many ways - but not with working out for you why your button no longer clicks as it did.

Also, please post in words not in phone text; many of our readers will not understand what you write if you use such abbreviations.

-Stewart
OK...SORRY about that...
Sep 9 '08 #113
puT3
145 100+
Sorry if I wasn't clear.

What I meant was to copy the SQL and post it in this thread. This will give me the opportunity to review the SQL you're ACTUALLY using at this point.
This is the SQL i used right at this point.
Expand|Select|Wrap|Line Numbers
  1. SELECT tPML.CallNumber,
  2.        tPML.AccessionNumber,
  3.        tPML.[ISBN/ISSN],
  4.        tA.[Author Name],
  5.        tPML.Title,
  6.        tPML.[Issue/Edition],
  7.        tS.[Topical Headings],
  8.        tPu.[Publication Name],
  9.        tPML.[Physical Description Area],
  10.        tPML.[Bibliography Notes],
  11.        tPML.CopyrightYear,
  12.        tPr.ProviderName,
  13.        tC.[Category Name],
  14.        tPML.Description
  15.  
  16. FROM (((([Printing Media Library] AS tPML LEFT JOIN 
  17.          Publication AS tPu
  18.   ON     tPML.PublisherID=tPu.[Publication ID]) LEFT JOIN
  19.          Author AS tA
  20.   ON tPML.AuthorID=tA.AuthorID) LEFT JOIN
  21.          Category AS tC
  22.   ON tPML.CategoryID=tC.CategoryID) LEFT JOIN
  23.          Provider AS tPr
  24.   ON tPML.ProviderID=tPr.ProviderID) LEFT JOIN
  25.          Subject AS tS 
  26.   ON tPML.SubjectID=tS.SubjectID;
Sep 9 '08 #114
puT3
145 100+
There's no way I can know this.

Clearly you have made some change that I'm completely unaware of.

This is why I have tried so hard to impress upon you the importance of clear and accurate communication. Without it I can't help you.
I didnt change anything from before..but never mind I try to look again what is wrong
Sep 9 '08 #115
NeoPa
32,556 Expert Mod 16PB
Try one thing for me :
From Access hit Alt-F11 (to go to VBA editor window).
Hit Ctrl-G (to open and go to the Immediate Pane).
Type in the following, and explain what happens (copy / paste the displayed line if it works).
Expand|Select|Wrap|Line Numbers
  1. ? Replace("ABCDE", "C", "*")
Sep 9 '08 #116
puT3
145 100+
Try one thing for me :
From Access hit Alt-F11 (to go to VBA editor window).
Hit Ctrl-G (to open and go to the Immediate Pane).
Type in the following, and explain what happens (copy / paste the displayed line if it works).
Expand|Select|Wrap|Line Numbers
  1. ? Replace("ABCDE", "C", "*")
For this,when I try a message box appear with message "The macros in this project in this are disabled.Please refer to the online help or documentation to determine how to enable macros".

I already found the solution -the problem is the macro is disabled thats why the button do not work....Everytime I open the database there is a Security Warning saying some content are disabled,I have to click option to change the settings,so I want to know how do I make it automatically enable and I do not have to change the settings whenever I open the database.

Your posted code actually work and do not have problem,if not of the disabled macro...
The [Printing Media Library] appear to show every data,so how to make it appear line by line?

TQ and Sorry to everyone....
Sep 10 '08 #117
puT3
145 100+
You seems to have the similar problem that I had before I found a solution. All the suggestions you've received so far is very good.

This is my suggestion:

(1) Create a query based on your table ('Printing Table or whatever you call it")
(2) Create a form based on your query
(3) Edit the query
- Select the query you created and click on "View" from toolbar and select "SQL View"

Then edit the SQL as follow (make sure to change the variables to suite your need. This is just an example)

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![frmLibrary]![txtISBN] Long, [Forms]![frmLibrary]![txtAuthor] Long,[Forms]![frmLibrary]![txtTitle] Long;
  2. SELECT [Your Table Name Here].*
  3. FROM [Your Table Name]
  4. WHERE IIf(Forms![frmLibrary]!txtISBN="",(Not [Your Table Name].[ISBN]),True)
  5.  Or ([Your Table Name].[ISBN]=Forms![frmLibrary]!txtISBN) 
  6. And ((Forms![frmLibrary]!txtAuthor Is Null) 
  7. Or ([Your Table Name].Author Like "*" & Forms![frmLibrary]!txtAuthor & "*"))
  8. And ((Forms![frmLibrary]!txtTitle Is Null) 
  9. Or ([Your Table Name].Title Like "*" & Forms![frmLibrary]!txtTitle & "*"));
  10.  
  11.  
Save the SQL statements.

Then in the form you created, make some combo boxes and/or text box (whatever is appropriate for your need) in the form header. Just make sure that they are not bound to anything (unbound).

Then on the "Search" command code (VBA), add this:

Expand|Select|Wrap|Line Numbers
  1. Public cmdSearch_Click()
  2.   Dim strSQL As String                  'The criteria string set in Query
  3.     Dim lngLen As Long      
  4.  
  5. 'Use the value from text field and match it with ISBN column from your table
  6.     If Not IsNull(Me.txtISBN) Then
  7.         strSQL = strSQL & "([ISBN] = """ & Me.txtISBN & """) AND "
  8.     End If
  9.  
  10. 'Use key word "Like" to find text anywhere in the field.
  11.     If Not IsNull(Me.txtAuthor) Then
  12.         strSQL = strSQL & "([Author] Like ""*" & Me.txtAuthor & "*"") AND "
  13.     End If
  14.  
  15. 'Use key word "Like" to find text anywhere in the field.
  16.     If Not IsNull(Me.txtTitle) Then
  17.         strSQL = strSQL & "([Title] Like ""*" & Me.txtTitle & "*"") AND "
  18.     End If
  19.  
  20. 'See if the string has more than 5 characters (a trailng " AND ") to remove.
  21.     lngLen = Len(strSQL) - 5
  22.     If lngLen <= 0 Then     'Nah: there was nothing in the string.
  23.         MsgBox "No parameter(s). Please set parameter(s) and try again.", vbInformation, "No Parameter(s)!"
  24.     Else                    'Yep: there is something there, so remove the " AND " at the end.
  25.         strSQL = Left$(strSQL, lngLen)
  26.     'Print Debug Info to Immediate Window (Ctrl+G).
  27.         Debug.Print strSQL
  28.  
  29.     'Finally, apply the string as the form's Filter.
  30.         Me.Filter = strSQL
  31.         Me.FilterOn = True
  32.     End If
  33.  
The above will allow user to provide as many parameters as they wish to provide. You can search by key word or exact match for both the "Title" and "Author". If user type in "ISBN" number, it will return the matching record from the table in the current form. I think it is much simpler and cleaner to just display the results in the same form.

That's what I did for my database and it works just fine. I hope that helps.
Thank You very much for your help tkip
Sep 10 '08 #118
puT3
145 100+
However,if I search for something that do not have related data,the [Printing Media Library] will appear blank,I understand how..do u have idea to overcome this?

And in [Printing Media Library] for my [Author Name],[Category Name],[Publisher Name] and [Provider Name] is a combo box,when I search its empty,may I know why? do I need to change the control type?
Sep 10 '08 #119
puT3
145 100+
And in [Printing Media Library] for my [Author Name],[Category Name],[Publisher Name] and [Provider Name] is a combo box,when I search its empty,may I know why? do I need to change the control type?
For this question please ignore it,I already found it.
Sep 10 '08 #120
NeoPa
32,556 Expert Mod 16PB
...
Your posted code actually work and do not have problem,if not of the disabled macro...
The [Printing Media Library] appear to show every data,so how to make it appear line by line?

TQ and Sorry to everyone....
Well, that gave us all a laugh anyway :D so no problem.

If you want a way of signing your database project so that Access recognises it as safe without prompting the operator, then post a question on that. It is a completely separate question, but would be worthwhile I expect.

As to your last question, I suspect you need to set the Default View of your form to Continuous Forms, although I don't really recognise the problem from your description. Try it out, and if it doesn't solve your problem then post back explaining exactly what the symptoms of the problem are.
Sep 10 '08 #121
puT3
145 100+
Well, that gave us all a laugh anyway :D so no problem.

If you want a way of signing your database project so that Access recognises it as safe without prompting the operator, then post a question on that. It is a completely separate question, but would be worthwhile I expect.

As to your last question, I suspect you need to set the Default View of your form to Continuous Forms, although I don't really recognise the problem from your description. Try it out, and if it doesn't solve your problem then post back explaining exactly what the symptoms of the problem are.
I already change it to Continuous Form....

I have a problem where there is multiple of same name data in the table,when I search for it,the result form [Printing Media Library] appear empty...For example,if I try to find an author with keywords 'micheal',it should appear all the data related to it and the name which have the name 'micheal' but instead, the form appear empty...It happen to several data too for Author Name (Author option button)
Sep 11 '08 #122
puT3
145 100+
Alright...So how to make the [Printing Media Form] have a checkbox at each result and then the complete result appear on other form?
Sep 11 '08 #123
NeoPa
32,556 Expert Mod 16PB
I already change it to Continuous Form....

I have a problem where there is multiple of same name data in the table,when I search for it,the result form [Printing Media Library] appear empty...For example,if I try to find an author with keywords 'micheal',it should appear all the data related to it and the name which have the name 'micheal' but instead, the form appear empty...It happen to several data too for Author Name (Author option button)
The most obvious thing that springs to mind here is your mis-spelling of 'Michael'. However, you say this is not only happening with this data but others too.

Unfortunately, yet again, you leave us with very little information to work with.

Does this problem only occur when using the "search by author" option?
Sep 11 '08 #124
NeoPa
32,556 Expert Mod 16PB
Alright...So how to make the [Printing Media Form] have a checkbox at each result and then the complete result appear on other form?
Let's leave this until you have [Printing Media Form] working properly shall we.

When we are ready to get on to this, we will need an understanding of what you mean by "the complete result".
Sep 11 '08 #125
puT3
145 100+
The most obvious thing that springs to mind here is your mis-spelling of 'Michael'. However, you say this is not only happening with this data but others too.

Unfortunately, yet again, you leave us with very little information to work with.

Does this problem only occur when using the "search by author" option?
Ooooh ok.....Thats Ok,I re-check everything again it is ok,I just mis-spell "Michael"...Sorry...and...TQ...

I want to ask another thing,if the search is not found,how to let the user know there is no data found instead of letting the [Printing Media Library] appear empty...
Sep 12 '08 #126
puT3
145 100+
Let's leave this until you have [Printing Media Form] working properly shall we.

When we are ready to get on to this, we will need an understanding of what you mean by "the complete result".
what I mean is that in [Printing Media Library] form,only partial info of the book appear and all other details will appear on another form...

For example,if the user search for an author in [Printing Media Library] form will list the name of the author,title of the book,year published and ISBN/ISSN number,when the user click on the check box,only then the full details (the Call Number,Description,Bibliography,Publisher Name,....) of the selected check box will be display....Is this possible?
Sep 12 '08 #127
puT3
145 100+
The reason is I want to print the result...or is there any any other way so that I can print the search result?
Sep 12 '08 #128
NeoPa
32,556 Expert Mod 16PB
Ooooh ok.....Thats Ok,I re-check everything again it is ok,I just mis-spell "Michael"...Sorry...and...TQ...

I want to ask another thing,if the search is not found,how to let the user know there is no data found instead of letting the [Printing Media Library] appear empty...
When it's empty, send a message using MsgBox() then either clear the filter or revert it to another setting you may prefer (or maybe even close it if it's not required at that point). This can be done from within the Form_Open() event of [Printing Media Library] quite conveniently.
Sep 12 '08 #129
NeoPa
32,556 Expert Mod 16PB
what I mean is that in [Printing Media Library] form,only partial info of the book appear and all other details will appear on another form...

For example,if the user search for an author in [Printing Media Library] form will list the name of the author,title of the book,year published and ISBN/ISSN number,when the user click on the check box,only then the full details (the Call Number,Description,Bibliography,Publisher Name,....) of the selected check box will be display....Is this possible?
Indeed it is.

You would simply open the new form (based on a table or query displaying all the info you want), passing the required record by setting and using another filter string.
Sep 12 '08 #130
NeoPa
32,556 Expert Mod 16PB
The reason is I want to print the result...or is there any any other way so that I can print the search result?
A form or report can both be printed easily enough.

They are both opened in similar ways too, so nothing too complicated there.
Sep 12 '08 #131
puT3
145 100+
Indeed it is.

You would simply open the new form (based on a table or query displaying all the info you want), passing the required record by setting and using another filter string.
Ok...But how do I do this?I dont really understand about this part "passing the required record by setting" and "using another filter string." Sorry Im on weekend break,i didnt open this for sometimes
Sep 15 '08 #132
NeoPa
32,556 Expert Mod 16PB
No worries about the posting delay. We always have enough to keep us busy.

As far as showing and printing a detailed item on a form or in a report is concerned, you should be able to repeat what we did in this thread.

If you remember, the [Printing Media Library] was designed and opened in a very similar way.

If you're still confused, start off by deciding whether a form or report is what you want, then we'll go through the steps to get this done. The first step after that decision will be to design the form/report in the way similar to the instructions for [Printing Media Library].
Sep 15 '08 #133
puT3
145 100+
Im a bit confuse,I think I would like to make a report...So,I create the report and make the record source to a query that I made for the [Printing Media Library] right? Is it ok I put the checkbox at the [Printing Media Library] now? Next,is the coding right?
Sep 16 '08 #134
NeoPa
32,556 Expert Mod 16PB
Im a bit confuse,I think I would like to make a report...So,I create the report and make the record source to a query that I made for the [Printing Media Library] right?
...
This is only right if the query has all the data available that you want to display. If so, then that's good. We have saved some time.
...
Is it ok I put the checkbox at the [Printing Media Library] now? Next,is the coding right?
I would consider adding a Command Button instead. A CheckBox indicates intention to do something at some time, whereas a Command Button says "Do This Now!".

We have no coding as yet (I haven't put any in and you haven't told me about any).
Sep 16 '08 #135
puT3
145 100+
This is only right if the query has all the data available that you want to display. If so, then that's good. We have saved some time.

I would consider adding a Command Button instead. A CheckBox indicates intention to do something at some time, whereas a Command Button says "Do This Now!".

We have no coding as yet (I haven't put any in and you haven't told me about any).
the query has all the data that I want to display....

so,is every line of result will have the command button or only one command button to indicate the chosen line?

for the coding,what is it do u need?
the reports name is [Printing Search Result],the record source is form query [QueryDef]
all data control are text box and the form is [Printing Media Library] where th report will have data from...
Sep 17 '08 #136
NeoPa
32,556 Expert Mod 16PB
the query has all the data that I want to display....
Sounds good. The report simply needs to be designed in a similar way to [Printing Media Library]. It will also be opened in a similar way.
so,is every line of result will have the command button or only one command button to indicate the chosen line?
This can be done either way. If the Command Button is put in the Header or Footer section of the form, then there will only be the one. If it is put in the detail section it will duplicate for every record.
for the coding,what is it do u need?
the reports name is [Printing Search Result],the record source is form query [QueryDef]
all data control are text box and the form is [Printing Media Library] where th report will have data from...
I think maybe we need to look again at the design somewhat. Do we want a report to come from the filtered form ([Printing Media Library])? Or do we want both the filtered form and the filtered report to come from the original form ([Search Form])?
Sep 17 '08 #137
puT3
145 100+
I think maybe we need to look again at the design somewhat. Do we want a report to come from the filtered form ([Printing Media Library])? Or do we want both the filtered form and the filtered report to come from the original form ([Search Form])?
Ok,the command button name is cmdDetail and I think I would like the report come from the filtered form...
Sep 18 '08 #138
puT3
145 100+
Back to your post #129,I dont really know how to make the "when it's empty"...sorry i have to go back the post..
Sep 18 '08 #139
NeoPa
32,556 Expert Mod 16PB
When it's empty, send a message using MsgBox() then either clear the filter or revert it to another setting you may prefer (or maybe even close it if it's not required at that point). This can be done from within the Form_Open() event of [Printing Media Library] quite conveniently.
This code simply illustrates how you would determine, on opening the form, whether or not there is any data. THIS code closes the form if there is nothing to display. Your code can be more flexible if required.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     If Me.Recordset.EOF Then
  3.         Call MsgBox("Uh Oh!")
  4.         Cancel = True
  5.     End If
  6. End Sub
Sep 18 '08 #140
NeoPa
32,556 Expert Mod 16PB
Ok,the command button name is cmdDetail and I think I would like the report come from the filtered form...
What I suggest you do at this point is put together some code that you think is right for opening the report. Remember this is triggered by your new Command Button [cmdDetail].

When you've done that, I will go over it with you. We really need to move on from my just doing all the code for you. You will never make any progress this way. You're ready to start fledging ;)
Sep 18 '08 #141
puT3
145 100+
What I suggest you do at this point is put together some code that you think is right for opening the report. Remember this is triggered by your new Command Button [cmdDetail].

When you've done that, I will go over it with you. We really need to move on from my just doing all the code for you. You will never make any progress this way. You're ready to start fledging ;)
Ok I will try to do that...
Sep 19 '08 #142
puT3
145 100+
the recordsource is from the query right?

the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDetails_Click()
  2.  
  3. Dim strReportName As String
  4. Dim strCriteria As String
  5.  
  6. strReportName = "Printing Search Result"
  7. strCriteria = "[Title] = '" & Me![Title] & "'"
  8.         strCriteria = "[Author Name] = '" & Me![Author Name] & "'"
  9.         strCriteria = "[Publication Name] = '" & Me![Publication Name] & "'"
  10.         strCriteria = "[CallNumber] = '" & Me![CallNumber] & "'"
  11.         strCriteria = "[ISBN/ISSN] = '" & Me![ISBN/ISSN] & "'"
  12.  
  13. DoCmd.OpenReport strReportName, acViewPreview, strCriteria
  14.  
Sep 19 '08 #143
NeoPa
32,556 Expert Mod 16PB
This isn't too far off. Let's look at what we want to do with it.

Lines #1 to #6 and #13 are fine. We need to look at settting up the strCriteria in more detail though.

Firstly, notice that each line (#7 through #11) sets up strCriteria from scratch, effectively replacing the data on every subsequent line. This is the same as simply running line #11.

What we want to do here is to set up a long filter string with ALL of the items specified. For that we need to append (using &) one string after the other with "AND"s between them. Normally I use the Replace() function to fill out data in strings, but for this example I'll go with what you have used already.
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "(([Title] = '" & Me![Title] & "')"
  2. strCriteria = strCriteria & " AND ([Author Name] = '" & Me![Author Name] & "')"
  3. strCriteria = strCriteria & " AND ([Publication Name] = '" & Me![Publication Name] & "')"
  4. strCriteria = strCriteria & " AND ([CallNumber] = '" & Me![CallNumber] & "')"
  5. strCriteria = strCriteria & " AND ([ISBN/ISSN] = '" & Me![ISBN/ISSN] & "'))"
Of course, the easier way to do it, assuming all you've said so far is accurate, would be to say :
Expand|Select|Wrap|Line Numbers
  1. strCriteria = Me.Filter
This code will be running from a form that is already set to filter by the same criteria as you need for the report. Hey Presto!
Sep 19 '08 #144
puT3
145 100+
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "(([Title] = '" & Me![Title] & "')"
why this code do not need to be like this code
Expand|Select|Wrap|Line Numbers
  1. strCriteria = strCriteria & " AND ([Author Name] = '" & Me![Author Name] & "')"

Another thing,if I want to update things,for example I want to update the date of book return...
Sep 22 '08 #145
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. strCriteria = "(([Title] = '" & Me![Title] & "')"
why this code do not need to be like this code
Expand|Select|Wrap|Line Numbers
  1. strCriteria = strCriteria & " AND ([Author Name] = '" & Me![Author Name] & "')"
Consider a typical WHERE string. It has the format :
(A) AND (B) AND (C) AND ... AND (Z)
There is always one fewer "AND" than there are criteria. Each SUBSEQUENT line (NOT the first), needs an "AND" to continue on from what is already there. Does that make sense?
Another thing,if I want to update things,for example I want to update the date of book return...
I don't understand what you're trying to say/ask here. Sorry.
Sep 22 '08 #146
puT3
145 100+
What Im trying to ask is I want to update the table using form because now I need to add 2 new field(was asked by supervisor) which are borrowDate and returnDate in [Printing Media Library] table (which i already add to the table)....So, I want to used a form to update the date whenever the user return the book/media...Does it involve any coding?
Sep 23 '08 #147
puT3
145 100+
Please ignore the previous question, I already find the solution...

However, Im having a problem with the previous coding.When i run it, a message box appear with this error

Expand|Select|Wrap|Line Numbers
  1. Run-time error '3011'
  2.  
  3. The Microsoft Office Access database engine could not find the object '(([Title] = 'Design for six sigma. Innovation for Enhanced Competitiveness') 
  4. AND ([Author Name] = 'Greogry H.Watson') 
  5. AND ([Publication Name] = 'GOAL/QPC') 
  6. AND ([CallNumber] = '1') 
  7. AND ([ISBN/ISSN] = '1-56781-078-x'))'. 
  8. Make sure the object exits and that you spell its name and the path name correctly.
  9.  
what is wrong?

the report name is [Printing Search Result] with recordsource of [QueryDef]....I want the report to have its data from filtered form [Printing Media Library]
In [Printing Media Library] it has a button name [cmdDetails] which will linked to the report when click

the coding i use is
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintingReport_Click()
  2.  
  3.     Dim strReportName As String
  4.     Dim strCriteria As String
  5.  
  6.     strReportName = "Printing Search Result"
  7.     strCriteria = "(([Title] = '" & Me![Title] & "')"
  8.     strCriteria = strCriteria & " AND ([Author Name] = '" & Me![Author Name] & "')"
  9.     strCriteria = strCriteria & " AND ([Publication Name] = '" & Me![Publication Name] & "')"
  10.     strCriteria = strCriteria & " AND ([CallNumber] = '" & Me![CallNumber] & "')"
  11.     strCriteria = strCriteria & " AND ([ISBN/ISSN] = '" & Me![ISBN/ISSN] & "'))"
  12.  
  13.     DoCmd.OpenReport strReportName, acViewPreview, strCriteria
  14.  
Sep 23 '08 #148
puT3
145 100+
Another question I want to asked,is it possible to keep the old data after being update?
For example, someone lend a book at a certain e.q.23/09/08 and return it 25/09/08 then someone else lend the same book on 27/09/08...I want to keep the previous date as a history,maybe in table or report..how can i do this?
Sep 23 '08 #149
NeoPa
32,556 Expert Mod 16PB
However, Im having a problem with the previous coding.When i run it, a message box appear with this error
Expand|Select|Wrap|Line Numbers
  1. Run-time error '3011'
  2.  
  3. The Microsoft Office Access database engine could not find the object '(([Title] = 'Design for six sigma. Innovation for Enhanced Competitiveness') 
  4. AND ([Author Name] = 'Greogry H.Watson') 
  5. AND ([Publication Name] = 'GOAL/QPC') 
  6. AND ([CallNumber] = '1') 
  7. AND ([ISBN/ISSN] = '1-56781-078-x'))'. 
  8. Make sure the object exits and that you spell its name and the path name correctly.
what is wrong?
...
the coding i use is
Expand|Select|Wrap|Line Numbers
  1. ...
  2.     DoCmd.OpenReport strReportName, acViewPreview, strCriteria
You are missing a parenthesis. The parameters are positional. You have called it passing strCriteria as a FilterName instead of a WhereCondition.
Sep 23 '08 #150

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

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
1
by: Jack-of-all-traits | last post by:
This is a big problem and I really need help, no one seems to know how to solve this problem. I want to take the data from a record in a particular a field that contains the names of generic...
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?
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...
7
by: John | last post by:
hi, i have created a search form, and i want to search for a specific item in a field. e.g. i have a field called colour, which has record1 = 'red, blue, green' and another record2 = 'red' ...
3
by: vonclausowitz | last post by:
Hi All, I was thinking of creating a table in my database to index all words in the database. That way I can quickly search for one or more words and the index table will return the words and...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
1
by: captainmorgan | last post by:
I have included an unbound field called which is used to quickly move to the desired record, by searching the last name field. I have been using this code for a few years, with only one...
9
by: AMBLY | last post by:
Hello ! Hope someone might be able to help me with this one. I run Access2000 on XP. I have a form : frmONE- which contains a txt field: ctrCTN from my table/database. The values in ctrCTN are...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.