By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Parameter Question

n8kindt
100+
P: 221
this is a very basic question but i might be making it more complicated than it should be. if i were to have a query with the following code

Expand|Select|Wrap|Line Numbers
  1. SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name]
  2. FROM Tbl1
  3. WHERE (((Tbl1.ID)=[forms]![frmTest].[id]));
it will automatically pull whatever is in the frmTest's id value.

now, what if i decide that for a particular case i don't want the ID criteria? if frmTest is closed it will prompt me to enter in data to replace [forms!test.id]. if i changed the criteria to Nz([forms!test.id],0) it would fill in the criteria as zero without a prompt. so, instead of using zero, is there a command that can be used to tell the query not to use any criteria and run the query like as if there were nothing in the where statement?

this is also related to when i make a query def parameter in DAO and decide i don't want a parameter in certain situations. how would i bypass the prompt? i have gotten around this by using if/then statements but i'm thinking there is an easier way.

i tried explaining this question the best i could. but it still might be confusing. please let me know if you need more clarification on my question. thanks!
Jun 18 '08 #1
Share this Question
Share on Google+
5 Replies


ADezii
Expert 5K+
P: 8,616
Howse about?
Expand|Select|Wrap|Line Numbers
  1. If IsClosed("<Your Form Name Here>") Then
  2.   SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name] FROM Tbl1
  3. Else
  4.   SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name]
  5.   FROM Tbl1
  6.   WHERE Tbl1.ID = [forms]![frmTest].[id];
  7. End If
Expand|Select|Wrap|Line Numbers
  1. Function IsClosed(ByVal strFormName As String) As Boolean
  2. 'Returns True if the specified Form is closed , otherwise returns False
  3. Const conObjStateClosed = 0
  4. Dim intCounter As Integer
  5. Dim blnFormExists As Boolean
  6.  
  7. blnFormExists = False       'initialize
  8.  
  9. 'Let's see if the Form actually exists in the Database
  10. For intCounter = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
  11.   If CurrentDb.Containers("Forms").Documents(intCounter).Name = strFormName Then
  12.     blnFormExists = True
  13.       Exit For
  14.   End If
  15. Next
  16.  
  17. If blnFormExists Then
  18.   'Form exists, but is it Closed?
  19.   If SysCmd(acSysCmdGetObjectState, acForm, strFormName) = conObjStateClosed Then
  20.     IsClosed = True
  21.   Else
  22.     IsClosed = False
  23.   End If
  24. Else
  25.   MsgBox "The Form (" & strFormName & ") does not exist in the Current Database", _
  26.          vbExclamation, "Form Does Not Exist"
  27. End If
  28. End Function
Jun 18 '08 #2

JKing
Expert 100+
P: 1,206
Out of curiousity what is the query being used for? By that I mean is the end result to display the query to a user? Or is it being used to supply data to a form or report?

The reason I ask is because that if you write a query that has no where clause to begin with you can add the where condition on the fly to filter your form/report. I'm not sure if it's what you are looking for but it is something to think about. This would also handle the situation where you want all data returned.
Jun 18 '08 #3

n8kindt
100+
P: 221
Howse about?
Expand|Select|Wrap|Line Numbers
  1. Function IsClosed(ByVal strFormName As String) As Boolean
  2. 'Returns True if the specified Form is closed , otherwise returns False
  3. Const conObjStateClosed = 0
  4. Dim intCounter As Integer
  5. Dim blnFormExists As Boolean
  6.  
  7. blnFormExists = False       'initialize
  8.  
  9. 'Let's see if the Form actually exists in the Database
  10. For intCounter = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
  11.   If CurrentDb.Containers("Forms").Documents(intCounter).Name = strFormName Then
  12.     blnFormExists = True
  13.       Exit For
  14.   End If
  15. Next
  16.  
  17. If blnFormExists Then
  18.   'Form exists, but is it Closed?
  19.   If SysCmd(acSysCmdGetObjectState, acForm, strFormName) = conObjStateClosed Then
  20.     IsClosed = True
  21.   Else
  22.     IsClosed = False
  23.   End If
  24. Else
  25.   MsgBox "The Form (" & strFormName & ") does not exist in the Current Database", _
  26.          vbExclamation, "Form Does Not Exist"
  27. End If
  28. End Function
wow, do u create code from scratch and post it on these forums? i admire your dedication to vba! that is a major upgrade over the code i created. i'm afraid to say that i was wondering if there was a way to bypass using a function like that. i was just curious if there was a simple command i could put in the criteria. for example, if i put the IS NULL command (idk if it's called a command, could be keyword.... whatever the technical name for it would be) in the criteria, it will return all the records that have null values for that field. the opposite goes for IS NOT NULL. it returns all the records that are not null. i was wondering if there was a command like (and i'm making this up) RETURN ALL and no criteria will be applied to that field in the where statement--which would return ALL records--no matter what the field contains. that way, i can fill the query parameter with "johnson" and it would return all records containing "johnson." but if i want to return all records, i could simply fill the query parameter with RETURN ALL. i don't know if a method of any sort exists for this or not but that's why i'm asking.

i just got to thinking that maybe to return all records, i would have to fill the parameter with IS NOT NULL OR IS NULL? i'm not sure how i would do that in the case of the querydefs example b/c it would be looking for a string and would simply return records that contain "is null or is not null" in the record.

i'm sorry i know i haven't describe this all that well. i've sat on this post for a while trying to figure out how to put into the best terms i can.
Jun 18 '08 #4

n8kindt
100+
P: 221
Out of curiousity what is the query being used for? By that I mean is the end result to display the query to a user? Or is it being used to supply data to a form or report?

The reason I ask is because that if you write a query that has no where clause to begin with you can add the where condition on the fly to filter your form/report. I'm not sure if it's what you are looking for but it is something to think about. This would also handle the situation where you want all data returned.
ok, i just created a new example. in the past, this is what i have done:

Expand|Select|Wrap|Line Numbers
  1.  
  2. If IsNull(Forms!StartEnd!FCFilter) = True Then
  3.  
  4.   Set qdf = db.QueryDefs("qrySource4Email")
  5.   Set rs = qdf.OpenRecordset()
  6. Else
  7.   Set qdf = db.QueryDefs("qrySource4EmailFiltered")
  8.   qdf.Parameters("[FCID]") = Forms!StartEnd!FCFilter
  9.   Set rs = qdf.OpenRecordset()
  10. End If
i would rather simply have this line of code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set qdf = db.QueryDefs("qrySource4EmailFiltered")
  3.   If IsNull(FCFilter) = False Then
  4.     qdf.Parameters("[FCID]") = Forms!StartEnd!FCFilter
  5.   Else
  6.     qdf.Parameters("[FCID]") = fill in blank 'i want this _
  7.               'to return all records... if i set it to "" it returns nothing
  8.   End If
  9. Set rs = qdf.OpenRecordset()
this is a simple scenario of what i might run into. but there are many other instances besides this. hopefully this example paints a better picture?
Jun 19 '08 #5

n8kindt
100+
P: 221
oh my gosh i think i finally figured it out. i think the theoretical RETURN ALL statement i had been looking for is actually an asterisk! *

duh. i'd seen the asterisk used many times before but never put two and two together. well now i feel like an idiot lol.
Jun 19 '08 #6

Post your reply

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