473,761 Members | 10,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cascading Lists for a form

kcdoell
230 New Member
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 1961
kcdoell
230 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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
9744
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
2086
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 chooses the department they want and then the corresponding surnames from that department can be chosen from the Surname box and then the Forename depending on which Surname they chose. I then have a command button which produces the results of the...
0
1169
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 on a postback, is this possible? At the moment when posting back the cascading dropdown the items collection contains only one item, the item selected.
4
64631
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 determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
4
3496
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 below. tblOrg OrgID, AutoNumber, PK ZipID, Number, FK tblState StateID, AutoNumber, PK
3
3988
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 list will 'display in the drop down list of CboSegment With Me! If IsNull(Me!cboDivision) Then
18
2117
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 new challenge which I'm not sure how to go about. Here is my situation: I presently have 2 combo boxes (cboBuilding, cboRoom) and which are properly cascading. That's great, but now I want to be able to pull the RoomDescription for the room that...
7
5840
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 currently trying to set up a whole pile of cascading combo boxes of different levels of complexity, so I started with the easiest set - and can't even get that to work (even using the tutorial on this site at...
3
1479
by: Outback | last post by:
Hi. Windows XP + Access 2002. I have three tables. tblMakes ======= MakeKey (PK) Make tblModels
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.