473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

having trouble opening recordset

I am trying to create a from with a series of combo boxes that each
query a different field (called Specific01, Specific02 etc., except
the first field which is called Condition). Each combo box has a SQL
statement in it's rowsource so it will only display distinct records
in it's field where all the previous fields match the choices chosen
in previous combo boxes, so eventually your choices will be narrowed
down until you come up with a final answer (i.e. the rowsource for the
final combo box only has one record). If this final answer is reached,
rather than displaying it in a new combo box's rowsource I want a text
box to display the answer. I am trying to put a piece of code into the
after update event of each combo box as below (this is what appears in
the first combo box, cboCondition):

Dim myConnection As ADODB.Connectio n
Dim myRecordSet As New ADODB.Recordset
Dim strSQL As String
strSQL = Me.cboSpecific0 1.RowSource
Debug.Print strSQL
Set myConnection = CurrentProject. Connection
myRecordSet.Act iveConnection = myConnection
myRecordSet.Ope n strSQL, , adOpenStatic

If myRecordSet.Rec ordCount 1 Then
Me.cboSpecific0 1.Visible = True
Me.cboSpecific0 1 = Null
Else
Me.cboSpecific0 1.Visible = False
Me.txtResult = myRecordSet.Fie lds(3).Value
Me.txtResult.Vi sible = True
Me.txtResult.Re query

myRecordSet.Clo se
End If

so if the next combo box (cboSpecific01) will only contain one record,
it is not shown and instead txtResult displays this final answer. If
it contains more than one choice, the next combo box (cboSpecific01)
is displayed.

For the above case, strSQL contains "SELECT DISTINCT
tblSpecifics.Sp ecific01 FROM tblSpecifics WHERE (([Condition]=Forms!
frmMain!cboCond ition)); ".

When I run the code I get the following message: "Run time error
'-2147217904 (80040e10)': No value given for one or more required
parameters" and the myrecordset.ope n line is highlighted. Before this
I tried using a DCount function instead of recordsets but I couldn't
get this to work either: I just got a "You cancelled the previous
operation" error message.

Can anyone see where I am going wrong? Any help would be much
appreciated.
Dec 8 '07 #1
1 1900
On Dec 8, 8:09 am, omar.nor...@gma il.com wrote:
I am trying to create a from with a series of combo boxes that each
query a different field (called Specific01, Specific02 etc., except
the first field which is called Condition). Each combo box has a SQL
statement in it's rowsource so it will only display distinct records
in it's field where all the previous fields match the choices chosen
in previous combo boxes, so eventually your choices will be narrowed
down until you come up with a final answer (i.e. the rowsource for the
final combo box only has one record). If this final answer is reached,
rather than displaying it in a new combo box's rowsource I want a text
box to display the answer. I am trying to put a piece of code into the
after update event of each combo box as below (this is what appears in
the first combo box, cboCondition):

Dim myConnection As ADODB.Connectio n
Dim myRecordSet As New ADODB.Recordset
Dim strSQL As String
strSQL = Me.cboSpecific0 1.RowSource
Debug.Print strSQL
Set myConnection = CurrentProject. Connection
myRecordSet.Act iveConnection = myConnection
myRecordSet.Ope n strSQL, , adOpenStatic

If myRecordSet.Rec ordCount 1 Then
Me.cboSpecific0 1.Visible = True
Me.cboSpecific0 1 = Null
Else
Me.cboSpecific0 1.Visible = False
Me.txtResult = myRecordSet.Fie lds(3).Value
Me.txtResult.Vi sible = True
Me.txtResult.Re query

myRecordSet.Clo se
End If

so if the next combo box (cboSpecific01) will only contain one record,
it is not shown and instead txtResult displays this final answer. If
it contains more than one choice, the next combo box (cboSpecific01)
is displayed.

For the above case, strSQL contains "SELECT DISTINCT
tblSpecifics.Sp ecific01 FROM tblSpecifics WHERE (([Condition]=Forms!
frmMain!cboCond ition)); ".

When I run the code I get the following message: "Run time error
'-2147217904 (80040e10)': No value given for one or more required
parameters" and the myrecordset.ope n line is highlighted. Before this
I tried using a DCount function instead of recordsets but I couldn't
get this to work either: I just got a "You cancelled the previous
operation" error message.

Can anyone see where I am going wrong? Any help would be much
appreciated.
I have had the exact same problem in the past. What you need to do is
pass parameters to that command/recordset. Your Forms!frmMain!
cboCondition is a parameter in the query so you must pass that
parameter to the command that will make the recordset. I am sorry if
my syntax is off a bit, I use DAO and not ADO on a regular basis, but
you should get the jist ;)

Dim rs as new ADODB.recordset
Dim cmd As new ADODB.Command
Dim prm as new ADODB.Parameter
'set the parameter's reference to the first parameter (the only
parameter) of your command that
'represents your recordset
cmd.commandtext = cbo.rowsource
cmd.commandtype = <text type>
Set prm = cmd.Parameters( 0)
'set the actual value of the parameter to the value of Forms!frmMain!
cboCondition
prm.value = <THE ACTUAL VALUE OF Forms!frmMain!c boCondition>
Set rs = cmd.Execute()
'your rs should now have the proper data returned
Another way I do this technique (and I use it alot in my forms) is to
have an afterupdate routine for each combo box that explicitly loads a
new rowsource for the next combo box the user will enter (or you the
gotfocus() routine and load the rowsource on entering the combo box
each time -- this is a bit slower though).

Best regards,

Tim
Dec 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2582
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update command and i have also tried the BeginTrans and CommitTrans nothign seems to work and i am unable to...
17
3374
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem occurs, the same queries successfully return the expected data when run from non-ADO sources, such as from ISQL in Microsoft SQL Server. This problem predominantly occurs on multi-processor computers but has also been known to occur on single-processor...
9
2053
by: TD | last post by:
I am trying to add transactions to my code. The original code worked fine until I followed an example to setup transactions, now the code does strange things, but no error messages. Could someone please review my before and after code and tell me the proper way to add transactions to my code? Thanks, TD
59
7490
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's invalid operation or invalid parameter, I'm
1
5141
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() Dim MyDB As Database Dim rstTemp As Recordset Dim rstTemp2 As Recordset Set MyDB = CurrentDb()
2
3788
by: ARC | last post by:
Just curious if anyone is having issues with Acc 2007 once the number of objects and complexity increases? I have a fairly large app, with many linked tables, 100's of forms, queries, reports, and lots of vba code. I'm nearly finished with re-doing my app in access 2007, and just imported an add-in program, which has added even more forms, queries and linked tables. Every so often now, after opening many different screens, I'll...
0
8421
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
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.