473,405 Members | 2,421 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,405 software developers and data experts.

VBA Syntax for an IF statement using a subform

I am not very familar with VBA syntax, so any help will be much appreciated. I am using Access 2003.

I have a subform that I would like to filter with an if statement.

I have a main form with a customerID. On the subform I have a list of the productID available. I would like to write an if statement that would exclude showing any productID that have already been purchased by the customerID.

The main form includes customerID.

The subform includes customerID and productID
Jul 6 '10 #1
7 2365
patjones
931 Expert 512MB
Without knowing more about your situation (for instance, table and column names), it sounds like you're looking for a SQL query that performs the desired operation, instead of an If statement.

Pat
Jul 6 '10 #2
Okay..I think I figured out what I need to do, I just do not know how I get there.

I would like to Apply a Filter to a subform.

Main form is frmDirectoryListingsAndZips_DataEntry
SubForm is frmZip_info

The subform and the main form both contain the field OwnerID.

I would like the subform to filter out any ownerID records that match the ownerID on the main form.
Jul 7 '10 #3
patjones
931 Expert 512MB
You want only records that have the same ownerID as the main form, or records that do not have the same ownerID?

In order to proceed I would need to know what your table names are, what the pertinent fields are, what information you want in the sub-form, etc.

Pat
Jul 7 '10 #4
NeoPa
32,556 Expert Mod 16PB
Ah. I think I see now. It is only those products that are not already linked (purchased) that you're interested in yes?
Jul 7 '10 #5
I want records to appear on the subform that do not have the same ownerID as the main form.

The main form: frmDirectoryListingsAndZips_DataEntry populated from table: tblDirectoryListingsAndZips

The subform: frmZip_info populated from table: tblZip_info_wActiveFloristZips

Both tables have the field OWNER_ID

These are the fields that will be visable on the subform:
ZipCode, CityName, StateAbbreviation, Select, and OWNER_ID
Jul 7 '10 #6
nico5038
3,080 Expert 2GB
You don't need VBA to achieve this. Just the right query will do the job.

Just use a query like:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tblProducts WHERE NOT ProductID IN (SELECT ProductID FROM tblInvoices WHERE OWNER_ID =forms!frmDirectoryListingsAndZips_DataEntry!OWNER_ID )
  2.  
for your subform.

Getting the idea ?

Nic;o)
Jul 7 '10 #7
NeoPa
32,556 Expert Mod 16PB
I would agree there is no real need for VBA as the filtering is constant.

Some alternative SQL might be :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM   [tblZip_info_wActiveFloristZips]
  3. WHERE  [Owner_ID]<>Forms!frmDirectoryListingsAndZips_DataEntry.Owner_ID
PS. I'll take your post #6 to mean yes :) The extra info was definitely helpful mind.
Jul 8 '10 #8

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

Similar topics

2
by: Gadrin77 | last post by:
as a newbie to XSL, is it possible to mimic a SELECT/CASE statement using XSL? I tried a quickie and I kept getting errors either using PARAM or WITH-PARAM in the wrong place or VARIABLE. I...
1
by: municipiodeloiza | last post by:
This is the outline. I'm using a form (frmMain) as a Menu screen. Also I have a subform (frmSub) that shows aditional info for the menu option selected. When I focus one option on the main...
11
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
11
by: Frankie | last post by:
Hello: New user here...first post to group. I'm getting an SQL syntax error when I try to run the following query: $query = sprintf("SELECT itemNumber, entryDate, modifyDate, thumbnailURL,...
3
by: Robert | last post by:
I have a form with two subforms on it. both subs have the same controlsource. Subform1 is a continuous form that acts as an index. The second subform is a single record that the user will use to...
2
by: Maximus | last post by:
I need some help with a SQL statement. I currently have which works: strSQL = "SELECT * FROM mstJobs WHERE JobStatus = True" I need to query against a second table but I am not sure of the...
3
by: Widge | last post by:
I have a form which I have set up which uses a combo box to provide supplier names. When you select a supplier name, it runs a small piece of VBA SQL which populates a subform with Product Codes and...
0
by: eonblue20 | last post by:
Hello I\\\'m new to DB2 and I\\\'ve been trying to create the MERGE statement using PreparedStatements in Java as a requirement for a project I\\\'m working on, but I get the following message: ...
1
by: sds50 | last post by:
Error with Select Statement using the SQLDataAdapter Wizard -------------------------------------------------------------------------------- I am needing to setup the data adapter for my SQL...
3
by: mabrynda | last post by:
Good morning everybody. I have the following problem. I would like to use a table name as variable (readed directly from a form) in a SELECT sql statement. I can't find the proper syntax to make it...
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: 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
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:
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.