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

Print combobox search

Jan
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 can pick
information from either one or many and press a search button. See
code below for the "Case Select" that was used to make up the
comboboxes. Not a filtered list. My problem is that when I try to
print, it prints all records before the search. I need it to print
what I had just searched. This could be one or many records. I am
learning VB and it can follow it pretty good.

Private Sub cmdSearch_Click()
Dim i As Integer
Dim stWhere As String
Dim stDelim As String

For i = 0 To 12
Select Case i
Case 0: stDelim = "'" 'text data type
Case 1: stDelim = "'" 'text data type
Case 2: stDelim = "'" ' Text data type
Case 3: stDelim = vbNullString ' numeric data type
Case 4: stDelim = vbNullString ' numberic data type
Case 5: stDelim = "'" 'text data type
Case 6: stDelim = "'" ' text data type
Case 7: stDelim = vbNullString 'numeric data type
Case 8: stDelim = vbNullString 'numeric data type
Case 9: stDelim = "@" ' currency data type
Case 10: stDelim = "'" 'text data type
Case 11: stDelim = "'" 'text data type
Case 12: stDelim = "'" 'Text data type

End Select
If Nz(Me("Criteria" & i), vbNullString) <> vbNullString Then
If Me("Criteria" & i) <> "<All>" Then
stWhere = stWhere & " AND " & Me("Criteria" & i).Tag &
" = " & stDelim & Me("Criteria" & i) & stDelim
End If
End If
Next i
If stWhere <> vbNullString Then
stWhere = Mid$(stWhere, 6)
Me.Filter = stWhere
Me.FilterOn = True
Else
MsgBox "Please enter some criteria.", vbExclamation, "No
Criteria Entered"
End If
End Sub

Any help would be great!
Thanks, Jan
Nov 12 '05 #1
4 2383
Jan,

The problem is that all your search results go out of scope when the procedure,
Private Sub cmdSearch_Click(), is done; meaning they are no longer available to
the query your report is based on. Put the following code in the Click event of
a button to do what you want:
(This is pseudocode which you can use to create the actual code!)

DoCmd.OpenForm "YourSearchForm",,,,,acDialog
DoCmd.OpenReport "YourReport", acPreview

On your search form you need a button with the following code in the Click
event:
Me.Visible = False

On your search form, you have to remove all the ways the form can be closed. The
user has to click on the above button to get out of the search form.

Put the following code in the Close event of your report:
DoCmd.Close acForm, "YourSearchForm"

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Jan" <Ja*********@weatherford.com> wrote in message
news:8d**************************@posting.google.c om...
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 can pick
information from either one or many and press a search button. See
code below for the "Case Select" that was used to make up the
comboboxes. Not a filtered list. My problem is that when I try to
print, it prints all records before the search. I need it to print
what I had just searched. This could be one or many records. I am
learning VB and it can follow it pretty good.

Private Sub cmdSearch_Click()
Dim i As Integer
Dim stWhere As String
Dim stDelim As String

For i = 0 To 12
Select Case i
Case 0: stDelim = "'" 'text data type
Case 1: stDelim = "'" 'text data type
Case 2: stDelim = "'" ' Text data type
Case 3: stDelim = vbNullString ' numeric data type
Case 4: stDelim = vbNullString ' numberic data type
Case 5: stDelim = "'" 'text data type
Case 6: stDelim = "'" ' text data type
Case 7: stDelim = vbNullString 'numeric data type
Case 8: stDelim = vbNullString 'numeric data type
Case 9: stDelim = "@" ' currency data type
Case 10: stDelim = "'" 'text data type
Case 11: stDelim = "'" 'text data type
Case 12: stDelim = "'" 'Text data type

End Select
If Nz(Me("Criteria" & i), vbNullString) <> vbNullString Then
If Me("Criteria" & i) <> "<All>" Then
stWhere = stWhere & " AND " & Me("Criteria" & i).Tag &
" = " & stDelim & Me("Criteria" & i) & stDelim
End If
End If
Next i
If stWhere <> vbNullString Then
stWhere = Mid$(stWhere, 6)
Me.Filter = stWhere
Me.FilterOn = True
Else
MsgBox "Please enter some criteria.", vbExclamation, "No
Criteria Entered"
End If
End Sub

Any help would be great!
Thanks, Jan

Nov 12 '05 #2


Thank you so much! Great information. I am learning so much. You are
the only forum who would help me.

Jan
Houston, TX

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

Wait, I am still only getting what happened before the search. Did I
need to put the DoCmds on the Search button or the print button?

Jan
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4
The Docmds go on the Print button. When you click that button, your search form
opens and you set all your search criteria in the comboboxes. What you are
calling the Search button runs the one line of code, Me.Visible = False.

The acDialog causes the code to pause until your Search form either closes or
becomes not visible. When it does, the code resumes and opens your report. At
the point your report opens, your Search form needs to be open (but not visible)
so your report query can get its criteria. Your Search form needs to stay open
so when you print the report the report can run the report query again. That's
why you don't close the Search form until the report closes.

Steve
PC Datasheet

"Jan Crocker" <ja*********@weatherford.com> wrote in message
news:40*********************@news.frii.net...

Wait, I am still only getting what happened before the search. Did I
need to put the DoCmds on the Search button or the print button?

Jan
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wim van Rosmalen | last post by:
I've upgraded MS-Access 2002 to a MS-Access Project (adp), so now I have to deal with more sophisticated queries (may I call them so?) like stored procedures. I have a form with a combobox for...
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...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
4
by: JJGarcia | last post by:
Hi Everyone, I'll try to explain the process I'm following, I'm new to this so I'm triying the easy way first, probably the lasyest too! I created a new Project, drag in to it a SQLConnection,...
2
by: Robert_5032 | last post by:
I have a list of companies in a form. I want the users to be able to print in the name of the company they are looking for in a textbox and then ACCESS should update the (continius) form with...
7
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
1
by: Pascal Hagedorn | last post by:
Hello Alltogether, following problem is bugging me :) I am havin a Combobox where i can browse and select my articles. So far so good! Over the time my table "article" growed and now it is not...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
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...

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.