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

Cascading Lists for a form

kcdoell
230 100+
Hello:

I have been struggling with building a cascading list on a form that I created. My problem is that I am getting a "Datatype Mismatch in criteria expression" error that I can not seem to figure out. I hope someone can help...

The background is that I have two drop down boxes on a form called:

cboPolicyName
cboPolicyNumber

On the rowsource for the cboPolicyName I have it pointing to my table:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT tblPolicyName.PolicyName, tblPolicyName.PolicyNameID FROM tblPolicyName ORDER BY tblPolicyName.PolicyName; 
  2.  
This works fine and the dropdown box populates with my various "Policy Names"

On the After update event of that same control I have the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboPolicyName_AfterUpdate()
  2. 'When the Policy Name is selected, the appropriate Policy Number region list will
  3. 'display in the drop down list of CboPolicyNumber
  4.  
  5. On Error Resume Next
  6.    cboPolicyNumber.RowSource = "Select tblPolicyNumber.PolicyNumber " & _
  7.             "FROM tblPolicyNumber " & _
  8.             "WHERE tblPolicyNumber.PolicyNameID = '" & cboPolicyName.Value & "' " & _
  9.             "ORDER BY tblPolicyNumber.PolicyNumber;"
  10. End Sub
  11.  
I set my cboPolicyNumber control rowsource to be blank.

I am new at doing these types of cascading lists but I have looked at how they are created and I believe I did everything right. For some reason, I believe the After Update is where the error is occurring. I have looked at everything I can think of, making sure that everything is bound on column 1 and that that column is numeric.

Does anybody have any ideas what I can check or where I am going wrong???

Thanks,

Keith.
Mar 6 '08 #1
3 1943
kcdoell
230 100+
Hello:

I saw the "how to doc." that was written by Rabbit, and followed it to a tee...The end result worked perfectly though it was different approach than I had been reading about... I am not very familiar with the "Me." values.

Here was the solution:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboPolicyName_AfterUpdate()
  3. 'When the Policy Name is selected, the appropriate Policy Number list will
  4. 'display in the drop down list of CboPolicyNumber
  5.  
  6.     With Me![cboPolicyNumber]
  7.       If IsNull(Me!cboPolicyName) Then
  8.         .RowSource = ""
  9.       Else
  10.         .RowSource = "SELECT [PolicyNumber] " & _
  11.                      "FROM TblPolicyNumber " & _
  12.                      "WHERE [PolicyNameID]=" & Me!cboPolicyName
  13.       End If
  14.      Call .Requery
  15. End With
  16.  
  17. End Sub
  18.  
  19.  
The only problem I am having is that now my query I created using the Access interface wizard now comes up blank. In the criteria of that query I am pointing to the form:

[forms].[DataEntry].[cboPolicyName]
[forms].[DataEntry].[cboPolicyNumber]

If I manually input the policy name and number into the query it works.

Below is the SQL of that query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. PARAMETERS [forms].[DataEntry].[cboPolyNumber] Short, [forms].[DataEntry].[cboPolyName] Short;
  3. SELECT tblPolyNumber.PolicyNumber, tblPolyName.PolicyName, tblMainRes.ReIndexName, tblMainRes.Pages, tblMainRes.EffectiveDates, tblMainRes.ExpirationDate, tblMainRes.Volume, tblMainRes.Tab, tblMainRes.PolicyNumberID
  4. FROM (tblPolyName INNER JOIN tblPolyNumber ON tblPolyName.PolicyNameID = tblPolyNumber.PolicyNameID) INNER JOIN tblMainRes ON tblPolyNumber.PolicyNumberID = tblMainRes.PolicyNumberID
  5. WHERE (((tblPolyNumber.PolicyNumber)=[forms].[DataEntry].[cboPolyNumber]) AND ((tblPolyName.PolicyName)=[forms].[DataEntry].[cboPolyName]));
  6.  
  7.  
Does anybody know why it can not see the selections that have been chosen on my form?

Thanks,

Keith.
Mar 6 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. ...WHERE (((tblPolyNumber.PolicyNumber)=[forms].[DataEntry].[cboPolyNumber]) AND ((tblPolyName.PolicyName)=[forms].[DataEntry].[cboPolyName]));
  2.  
Does anybody know why it can not see the selections that have been chosen on my form?

Thanks,

Keith.
Hi Keith. If you are referring to two existing form fields you need to include their values in the WHERE clause as string literals (assuming both are strings):
Expand|Select|Wrap|Line Numbers
  1. WHERE (((tblPolyNumber.PolicyNumber) = '" & [forms].[DataEntry].[cboPolyNumber] & "') AND ((tblPolyName.PolicyName) = '" & [forms].[DataEntry].[cboPolyName] & "'"));
-Stewart
Mar 8 '08 #3
kcdoell
230 100+
Stewart:

I was in a rush last night to get out the door but just before doing so I solved it! In the end, it was my bound column in cboPolicyName. My code (AfterUpdate) was written to look for the PolicyNameID. That is why I had a syntax error when I changed my cboPolicyName to bound on 2. To solve I dropped in my PolicyNameID into my query and put my criteria there instead of the PolicyName field. I did the later and it worked error free!

Thanks for all your help!
Mar 11 '08 #4

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

Similar topics

2
by: Sam | last post by:
A) Destination Table with 4 Fields. 1) Last Name 2) First Name 3) State 4) Zip Code. B) Look up table State/Zip Code with 2 Fields
6
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user...
0
by: robert | last post by:
I am using the new beta 2 ajax control toolkit. When using the cascading drop-down obviously the items in the lists are generated through javascript, I would like to access these items serverside...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
4
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields...
3
kcdoell
by: kcdoell | last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box: Private Sub CboDivision_AfterUpdate() 'When the Division is selected, the appropriate Segment...
18
by: LosLobo | last post by:
Greetings all. I know that cascading lists are a common problem and in truth I my initial post here was to request help with my own, but then I figured out the right code. That being said, I have a...
7
by: Toireasa | last post by:
Hi, Newbie Access developer here, and my first post on this forum, so I might not get everything right - thanks in advance for your help and your patience! I'm using Access 2007, in XP. I'm...
3
by: Outback | last post by:
Hi. Windows XP + Access 2002. I have three tables. tblMakes ======= MakeKey (PK) Make tblModels
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?
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:
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.