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

Where Condition Query

Hi,

I have a question regarding placing the Where condition in this section of code

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Command219_Click()
  2.  
  3. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  4. If IsNull(Me!ContactID) Then
  5. MsgBox "Please select a valid record", _
  6. vbOKOnly, "Error"
  7. Exit Sub
  8. End If
  9. DoCmd.OpenReport "mailmerge", acViewPreview, , _
  10. "ContactID = " & Me!ContactID 
  11. end sub 
I need to insert 2 additional where conditions for the report, one being a checkbox and another testing for a value of 1.

The SQL would be

Expand|Select|Wrap|Line Numbers
  1.  WHERE (((Letters.PrintF)=-1) AND ((Letters.RecpID)=1)); 
Can anyone help me convert this into the VB?

Thanks
Dec 31 '07 #1
7 1981
jaxjagfan
254 Expert 100+
Hi,

I have a question regarding placing the Where condition in this section of code

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Command219_Click()
  2.  
  3. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  4. If IsNull(Me!ContactID) Then
  5. MsgBox "Please select a valid record", _
  6. vbOKOnly, "Error"
  7. Exit Sub
  8. End If
  9. DoCmd.OpenReport "mailmerge", acViewPreview, , _
  10. "ContactID = " & Me!ContactID 
  11. end sub 
I need to insert 2 additional where conditions for the report, one being a checkbox and another testing for a value of 1.

The SQL would be

Expand|Select|Wrap|Line Numbers
  1.  WHERE (((Letters.PrintF)=-1) AND ((Letters.RecpID)=1)); 
Can anyone help me convert this into the VB?

Thanks
I put the ContactID last since it seems to be a value coming from the form and the other values are hard coded.

"PrintF=-1 AND RecpID=1 AND ContactID = " & Me!ContactID

As long as it is a viable WHERE clause you don't need all of the brackets the QBE uses.
Dec 31 '07 #2
Hi Jaxjagfan

Thanks for the quick reply!

I gave it a go and it produced an error. I should have explained that ContactID is the main form and the PrintF and RecpID values are on a linked form.

The original code selects the current record displayed but I get an error when I try to further filter these results by using values form the letters form.

Apologies for not being clearer!
Dec 31 '07 #3
jaxjagfan
254 Expert 100+
Hi Jaxjagfan

Thanks for the quick reply!

I gave it a go and it produced an error. I should have explained that ContactID is the main form and the PrintF and RecpID values are on a linked form.

The original code selects the current record displayed but I get an error when I try to further filter these results by using values form the letters form.

Apologies for not being clearer!
Try this (assuming the name of the subform control is "Letters"):

"Me!Letters.PrintF=-1 AND Me!Letters.RecpID=1 AND ContactID = " & Me!ContactID

or you may have to use this format to reference the subform values:

Forms.YourMainFormName.SubformContainerName.Form.C ontrolName

What is the name of the main form?
Dec 31 '07 #4
Try this (assuming the name of the subform control is "Letters"):

"Me!Letters.PrintF=-1 AND Me!Letters.RecpID=1 AND ContactID = " & Me!ContactID

or you may have to use this format to reference the subform values:

Forms.YourMainFormName.SubformContainerName.Form.C ontrolName

What is the name of the main form?

My mainform is Contacts and the subform is Letters

I gave the above example and
Expand|Select|Wrap|Line Numbers
  1. "Forms.Contacts.Letters.Form.PrintF=-1 AND Forms.Contacts.Letters.Form.RecpID=1 AND ContactID = " & Me!ContactID 
a go but on running it i was asked to enter the parameter value. I can't think of what else I am missing.
Dec 31 '07 #5
jaxjagfan
254 Expert 100+
My mainform is Contacts and the subform is Letters

I gave the above example and
Expand|Select|Wrap|Line Numbers
  1. "Forms.Contacts.Letters.Form.PrintF=-1 AND Forms.Contacts.Letters.Form.RecpID=1 AND ContactID = " & Me!ContactID 
a go but on running it i was asked to enter the parameter value. I can't think of what else I am missing.
Look at the main form in design view. Select the control that contains the subform not the subform itself. Look at the properties of this control and see what its name is. Is it "Letters"?

FYI - You should get into the habit of satndardizing your naming. I'm not always consistent myself (but should be). It would be frmContacts, tblContacts, qryContacts, etc.
Dec 31 '07 #6
Look at the main form in design view. Select the control that contains the subform not the subform itself. Look at the properties of this control and see what its name is. Is it "Letters"?

FYI - You should get into the habit of satndardizing your naming. I'm not always consistent myself (but should be). It would be frmContacts, tblContacts, qryContacts, etc.
Actually now you mention, the mainform is called Contacts but the subform is called Letter Detail Form that is again placed in another form Letters which is then placed on the main form.

So it goes Contacts > Letters > Letter Detail Form.

Letter Detail Form being the one with the information needed.
Dec 31 '07 #7
Got sorted thanks, took me a while but finally got there.

I am going to have to tidy up the names as you said, would be alot easier to follow for me and others.

Thanks for the help!
Jan 2 '08 #8

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

Similar topics

4
by: stoppal | last post by:
I need some help. I am trying to write a query which does the following SELECT * from table1 where field1=(SELECT distinct field1 FROM table1 WHERE field2='2005' or field2='2010')
8
by: xixi | last post by:
hi, we are using db2 udb v8.1 on windows, i have a table contains over one million records, it has seperate own tablespace than others, with bufferpool size 250, i have created multiple views on...
8
by: John Welch | last post by:
I have a command button with the following code: DoCmd.OpenForm "frmSearchAssignments", , , "SearchAssignmentID = 1" (SearchAssignmentID is the PK, auto number) When it runs, the form opens but...
2
by: Sreedhar Vankayala | last post by:
Hi, I have a table IV00108wc which contains several thousand records in whcih ITEMNMBR is the primary key. I have a com+ object returning recordset which has ITEMNMBR and another details...
1
by: Peter Alberer | last post by:
Hi there, i have a problem with a query that uses the result of a plsql function In the where clause: SELECT assignments.assignment_id, assignments.package_id AS package_id,...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
2
by: Ely | last post by:
Can some one write me the code in Visual Basic for an expretion similar to the Where Condition to open a report? I can't use the Where Condition because it pop up a message of Microsoft database...
4
by: Jane T | last post by:
I appreciate how difficult it is to resolve a problem without all the information but maybe someone has come across a similar problem. I have an 'extract' table which has 1853 rows when I ask for...
8
by: SambhajiB | last post by:
Hi, I am using Access 2003 and .Net 2005. I have one problem in access query. I am trying to send the condtion of where clause through parameter to Access query as follows... PARAMETERS ...
5
by: MARIEDB2 | last post by:
Hello, I am struggling to build a query on a DB2 db wich does an update for multiple fields which are the result of a select query with where clause (using multiple tables in the condition). ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.