Help with VBA (open query)

I have one command button used to open a form. How can I change if I
wan to open a query instead of form? I try with this but it doesn't
works. Something wrong with the code?
Or I use the wrong method?
####
strQuery = "grouping" (query name)
DoCmd.openquery strQuery, , , strSQL
####

Private Sub openform_Click()
Dim strSQL As String
Dim strWhere As String

If Not IsNull(tool_id) Then
strWhere = strWhere & " AND tool_id= " & "'" & tool_id & "'"
End If

If Not IsNull(cboStatus) Then
strWhere = strWhere & " AND status= " & "'" & cboStatus & "'"
End If

If Not IsNull(strWhere) Then
strSQL = Mid$(strWhere, 6)
End If

strForm = "history"
DoCmd.openform strForm, , , strSQL

0
xiaodan86
5/24/2007 5:47:22 AM
access 16762 articles. 3 followers. Follow

1 Replies
693 Views

Similar Articles

[PageSpeed] 3

Hi

OpenQuery doesn't have the same parameters as OpenForm
(Have a look in the help)

The following would open your query...

strQuery = "grouping" (query name)
DoCmd.openquery strQuery

If you need the query to be filtered by tool_id etc then you need to use 
parameters in the query itself.

Regards

Andy Hull


"xiaodan86@hotmail.com" wrote:

> I have one command button used to open a form. How can I change if I
> wan to open a query instead of form? I try with this but it doesn't
> works. Something wrong with the code?
> Or I use the wrong method?
> ####
> strQuery = "grouping" (query name)
> DoCmd.openquery strQuery, , , strSQL
> ####
> 
> Private Sub openform_Click()
> Dim strSQL As String
> Dim strWhere As String
> 
> If Not IsNull(tool_id) Then
> strWhere = strWhere & " AND tool_id= " & "'" & tool_id & "'"
> End If
> 
> If Not IsNull(cboStatus) Then
> strWhere = strWhere & " AND status= " & "'" & cboStatus & "'"
> End If
> 
> If Not IsNull(strWhere) Then
> strSQL = Mid$(strWhere, 6)
> End If
> 
> strForm = "history"
> DoCmd.openform strForm, , , strSQL
> 
> 
0
Utf
5/24/2007 8:01:02 AM
Reply:

Similar Artilces:

Make a chart axis visible/invisible with VBA
(I posted this in the Programming newsgroup but realized it was probably more appropriate to post here...) Hello. I'm using Excel 2003. I have a chart on a page and I want to set the scale on the Y axis programatically with VBA. I have written code that does this successfully. The problem: The code will not work if the Y axis is hidden (which I want) - it throws an error saying it can't set the Maximum value. Where I need help: I'm having trouble writing the code to make the Y axis visible, then invisible again. The idea being that I'll display it, set the scale, ...

windows xp help please
I need some help please. When I download things it will only download to 99% then it stops and want completely download things. Is there anything I can do to fix this short of a reformat? -- thank you, coffee121858 Always state your full Windows version (e.g., WinXP SP3) when posting in a forum or newsgroup. Please do so in your next reply. In this case, also state your IE version. What anti-virus application or security suite is installed and is your subscription current? What anti-spyware applications (other than Defender)? What third-party firewall (if any)? Has a(...

Cumulative Query
Hello, Got a table look like this: Time UNITS 8:00 10 9:00 5 10:00 15 11:00 20 Would a query to will cumulate the sum of the units before the current one so it will look like this: Time UNITS 8:00 10 9:00 15 (it`s 10 + 5) 10:00 30 (it`s 10 + 5 + 15) 11:00 50 (it`s 10 + 5 + 15 + 20) it must be simple but i have no clue how alex wrote: >Got a table look like this: > >Time UNITS >8:00 10 >9:00 5 >10:00 15 >11:00 20 > > >Would a query to will cumulate the sum of the units before the curren...

Install Problems
CRM V1.2 Install Fails with: Setup was unable to install Microsoft CRM Server. Setup was unable to Create the Microsoft CRM databases. Failed to run script:Replication\p_DeleteSchedule.sql. HRESULT:80040E14. Unknown error. (80040E14) Environment: Win2k3 Enterprise SP1 SQL Server 2005 beta Exchange 2003 Standard SP1 Server Roles: File Server Print Server Application Server Domain Controller (Active Directory) DNS Server Please let me know if any other stats about the server would be helpful in diagnosing this issue. I would really like to get this software running. I am logged on as...

Fun with SQL and CRM Help needed
Ok. I've been tasked with setting the "Address Name" for every contact equal to the name of the parent company. I know I can write an SQL query to do this, I just can't figure out where the relationship is between contacts accounts and the customeraddressbase table. So, heres what I need to do: Open Contact, Get Contacts Parent Customer Name, Put Parent Customer Name into Address Name for the contacts main address. The database is relatively new, we just finished a very botched import from ACT! not to long ago. this is the latest "Fix" that I've been asked to...

labeling work sheet tabs pls.help
HI I would like to know if I can label the tabs of the work sheet with a date then the next sheet seven days later, then is there a autocomplete or some way of labeling 50 more worksheet without having to typw them all by hand. like draging the days of the week or months of the year in the rows of a sheet. thanks for the help steve Steve You received several options yesterday. Are you not seeing the replies to your posts? If not, this one is a waste of time<g> Google search results here....... http://snurl.com/1uay Gord Dibben Excel MVP - XL97 SR2 & XL2002 On Sat, 19 J...

Open Items
I have a client that uses open items for things like shipping. They have the price set to $0.00, and it marked Must enter price at the POS. The problem is when they put the price in it changes back to $0.00, and they have to put the price in again. I know this will happen if the item is on sale, but it's not. Anyone else have any ideas? This is a multi-part message in MIME format. ------=_NextPart_000_0037_01C92AFD.F5BBAE20 Content-Type: text/plain; charset="Utf-8" Content-Transfer-Encoding: quoted-printable If you are using Price levels, that is the source of the probl...

Excel 2007
On Windows XP SP2 using Excel 2007 I am unable to print from the Open file dialogue. Here is what I am doing: Clicking Open from the Office button Navigating to the file I would to Print Highlighting the document Selecting Print from the Tools menu in the lower left hand corner of the dialogue box The error message I receive states: Cannot print file. It then gives a series of possible reasons, none of which apply because I can print the document if I open it first and then print it normally. Also, I can use the above sequence to print the document if the document is already open. This ser...

IMF Not Updating HELP!
I'm having a problem and I hope someone can help. I configured IMF a couple of days ago. (Definitions are from 2005) It seems to be working great. I have the gateway set at 6 and the store at 4. So far getting very good results. But I can not update the definition files. I added the regisry key ContentFilterState and set to 1 I restarted SMTP service I triple check these settings, I've read all the documentation I can find on IMF. I've also checked to be sure I'm using Microsoft update and not WU. I go to Microsoft Update and press custom. I don't see the update listed....

Pinging Ed Bennett for help on this one
Ed, You were kind enough to help me create the following vba code for publisher 2k3 several month ago. I recently had to install a new m/b and all of my apps and for some reason this code _doesn't seem_ to work anymore. I say that because no longer do the toolbar buttons get created. I suspect it has something to do with my security. I self certified the original code and I am thinking maybe my certification is invalid. Would the best way to proceed be delete the vba code, recreate it (i.e. copy/paste back) and self cert again to get it to work? Or am I missing something basic here...

Making Folders Stay Open?
I have a couple of Personal Folders that I would like to stay open at all times. Mainly, I would like them to be open when I start Outlook 2003. Is there any way to set up a folder so that it stays open? Thanks, -barry Only your default folders. The other personal folders you will have to expand manually. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After furious head scratching, Barry F Margolius asked: | I have a...

How to MoveFirst, MoveNext, MovePrevious, MoveLast in LinQ To XMl Please Help
I have the Next XML var xml = new XElement( "clients", new XElement("client", new XAttribute("id",1), new XElement( "name", "Luis"), new XElement( "country", "Portugal") ), new XElement("client", new XAttribute("id",2), n...

Help on Stacked column graph
Hi, with the following group of data 1 2 3 4 a 10 10 30 5 b 30 5 32 42 c 10 12 15 28 I want to have a graph with 2 column s for each letter, one with the value of column 1 and another one with the sum of columns 2, 3 & 4 with different color for each value. I've seen that is possible in some built in graph but not sure how to make it Thanks -- Alvaro Alvaro wrote: > Hi, > > with the following group of data > 1 2 3 4 > a 10 10 30 5 > b 30 5 32 42 > c 10 12 15 28 > > I want to have a graph with 2 column s for each letter, one with the value > of ...

had a virus, now cannot open IE
I have icons on desktop..try to click aol or msn icon get reply cannot find file....same with trying to open from start..I had Total PC Defender and finally got rid of it with Malwarebytes. Did I delete something that maybe I shouldn't have? Chicken wrote: > I have icons on desktop..try to click aol or msn icon get reply > cannot find file....same with trying to open from start..I had Total > PC Defender and finally got rid of it with Malwarebytes. Did I > delete something that maybe I shouldn't have? First, we need to know the name of the malware. O...

Mac OSX How to open a .pub image.
I received an image in the .pub file format from a non-computer literate person. In what program can I open it, or to what program can I import it to - being on Mac OSX 10.3.9 as I am? Thanks! --Doc. On 7/15/05 6:30 PM, in article BEFDB139.E017%drcocktail@bigfoot.com, "DrCocktail" <drcocktail@bigfoot.com> wrote: > I received an image in the .pub file format from a non-computer literate > person. In what program can I open it, or to what program can I import it to > - being on Mac OSX 10.3.9 as I am? It won't open in anything on the Mac. It needs Microsoft Pu...

Novice at formulas needs help
Please remember...I'm a novice at EXCEL...self-taught...I want to write a formula that will convert what is in one column to another column based on info in yet another column.... If D=1 and K=B then L=NH...another example... If D=7 through 12(as in grade in school) and K=D then L=IH --- Message posted from http://www.ExcelForum.com/ Hi use the IF formula. E.g. if your target cell is C1 enter the follwoing =IF(A1="D",B1,"no value") this will enter the value of B1 in C1 if A1 is "D" have a look at the Excel helpfile for the IF formula Frank =IF(AND(D1...

Publisher can't open a file it just created
Working with Publisher 2003 we just reinstalled it on a computer because it started have problems opening publisher 2003 files. If I create a new file in publisher then save it, when I try to open it again it tells me that it can not open this file. Has anyone else run into this? It happened on another computer once before and we formated and reinstalled windows. I'd like to not have to re install windows if I can help it. Chris Are you saving the file to the hard drive? Do you have Norton? If so disable "script blocking" and in Norton's options disable "Of...

Non specific error on opening Outlook 2000 on Windows 2000 Pro system
"Cannot Open Microsoft Outlook. A program error has occurred. Quit Outlook and Windows and then start again." This happens with all profiles on the system. I've repaired Office, reinstalled Office, then uninstalled and reinstalled Office (and redownloaded and applied all patches). It still errors. Other Office apps open just fine. Outlook does connect to the Exchange server, since I can configure services and it recognizes the LAN ID. Any thoughts? Does it start in safe mode, go to Start > Run > type "Outlook /safe" without the quotes "Paula&qu...

>>>Live Chat
On October 4, 2007, the Microsoft Dynamics Retail Management System (RMS) team will host an Open Forum Live Chat. In this chat, our experts will take questions on any Microsoft Dynamics RMS topic. If we get a high volume of questions during the Open Forum chat, our experts might not be able to respond to all of them within the chat timeframe. In that event, our experts will respond after the chat ends, to the extent possible, and their answers will be included in the transcript for the chat. The transcript will be posted to the using page.http://www.microsoft.com/dynamics/rms/using Si...

Create a statement query or report
I have a database with two tables. One is Project and has a ProjectID, ProjectNo, InvDate and InvAmt. Another table is ROA and has ProjectID, Date and Amt. How do I combine these two to make a statement with the data sorted by date? Thanks, Bill "Bill Allen" wrote: > I have a database with two tables. One is Project and has a ProjectID, > ProjectNo, InvDate and InvAmt. Another table is ROA and has ProjectID, Date > and Amt. > > How do I combine these two to make a statement with the data sorted by date? > > Thanks, > > Bill > > >...

Simple Query 12-09-09
I am quering a database with 10000 records and the end result of the query should be about 1500 records. It worked once and now it hangs for a bit and returns 29 million records. What causes that? -- CowichanDave On Dec 8, 11:23=A0pm, cowichandave <cowichand...@discussions.microsoft.com> wrote: > I am quering a database with 10000 records and the end result of the quer= y > should be about 1500 records. It worked once and now it hangs for a bit a= nd > returns 29 million records. What causes that? > -- > CowichanDave sounds like you have a join in there...

HELP! Using XMLTextWriter to write to a MemoryStream
I have the following code that is supposed to use the XMLTextWriter to write the XML to a MemoryStream: Dim ms As MemoryStream ms = New MemoryStream Dim xtw As New Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8) xtw.Formatting = Formatting.Indented xtw.Indentation = 2 xtw.QuoteChar = """"c xtw.WriteStartDocument(True) xtw.WriteComment("Data from DB") xtw.WriteStartElement("Data") xtw.WriteStartElement("Employee") xtw.WriteElementString("LastName", "Dillan") xtw.WriteElementString("FirstName", "Bob")...

Error Opening archive .pst
I have archived several years worth of Outlook data. I have created an archive file for each year, and moved the archives to CD. The file does not span CD's. The archive files were created some time ago, and I get an error when attempting to open them. Access denied. I opened them before... What is the trick...? Is it because they are on CD now...? or is it because I have migrated to a new version of Outlook (2003)...? or is it because I have changed user names from my business address when the archives were created to my personal outlook program at home...? i.e. userid changed..? ...

SqlXMLCommand Help?
This is a multi-part message in MIME format. ------=_NextPart_000_03DD_01C3B036.70396CC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I noticed an earlier post, Multiple External References in Transform - = Background to the problem - Long Post, where the poster referenced an = object entitled SqlXmlCommand. I am unable to find this object?=20 My requirement is thus. Read several tables from sql server 2000 db = with the auto xml feature and read them into a single XPathDocument. = Each of the tables need to be read as seperate call...

Access 2K7
I followed the directions here: http://support.microsoft.com/default.aspx?scid=kb;en-us;285820 When I run it, I'm getting the error: "438 Object doesn't support this property or method" It looks like it's breaking on this bit of code: ".Picture = strImagePath" Any idea what I'm doing wrong? Module code: Option Compare Database Option Explicit Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String On Error GoTo Err_DisplayImage Dim strResult As String Dim strDatabasePath As String Dim intSlashLo...