473,700 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

swapping recordsets on a form

I am trying to change the recordset that my form uses, but when I
requery my form, all of the textboxes display #Name?

Here is what I am trying to do:
The user enters a search term in a textbox clicks a button. The
form's recordset is then searched and when a matching record is found
it is added into a second recordset.
Then I set the form's recordset to the second recordset and requery,
with the intention that the form will now display the records that were
determined to have mathed the search term.
This is how I have done it:

Dim myTerm As String
myTerm = Me.Search_Box

Dim myRecordCount As Long

Dim rs1 As DAO.Recordset
Set rs1 = CurrentDb.OpenR ecordset("Selec t * from Case_List")
If rs1.EOF = False Then
rs1.MoveLast
End If

myRecordCount = rs1.recordCount
rs1.MoveFirst

Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
'now create our relevant fields
rs2.Fields.Appe nd "Case_ID", adInteger
rs2.Fields.Appe nd "Case_or_Issue" , adVarChar, 50
rs2.Fields.Appe nd "Case_Numbe r", adInteger
rs2.Fields.Appe nd "Client", adInteger

If Me.Frame_1 = 1 Then 'then we are searching on Party Name
'now loop through rs1 and see if the instr() function gets a
match, if so, add to rs2
rs2.Open
For i = 0 To myRecordCount - 1
If InStr(rs1!Case_ or_Issue, myTerm) > 0 Then 'we have a
match
rs2.AddNew Array("Case_ID" , "Case_or_Issue" ,
"Case_Numbe r", "Client"), Array(rs1!Case_ ID, rs1!Case_or_Iss ue,
rs1!Case_Number , rs1!Client)
rs2.Update
End If

If rs1.EOF = False Then
rs1.MoveNext
End If

Next 'next record
ElseIf Me.Frame_1 = 2 Then 'then we are searching on case
number
ElseIf Me.Frame_1 = 3 Then 'then we are searching on case ID

End If

Set Me.Recordset = rs2
Me.Requery

rs2.Close
rs1.Close

rs1 has all of the same field names as rs2, but rs2 does not have all
of the same field names as rs1. Is that where my problem is? Can
someone tell me how to fix this so that the rs2 records display on my
form?

Thanks,

Jody Blau

Feb 16 '06 #1
2 1846

"jodyblau" <jo******@gmail .com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
I am trying to change the recordset that my form uses, but when I
requery my form, all of the textboxes display #Name?

Here is what I am trying to do:
The user enters a search term in a textbox clicks a button. The
form's recordset is then searched and when a matching record is found
it is added into a second recordset.
Then I set the form's recordset to the second recordset and requery,
with the intention that the form will now display the records that were
determined to have mathed the search term.
This is how I have done it:

Dim myTerm As String
myTerm = Me.Search_Box

Dim myRecordCount As Long

Dim rs1 As DAO.Recordset
Set rs1 = CurrentDb.OpenR ecordset("Selec t * from Case_List")
If rs1.EOF = False Then
rs1.MoveLast
End If

myRecordCount = rs1.recordCount
rs1.MoveFirst

Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
'now create our relevant fields
rs2.Fields.Appe nd "Case_ID", adInteger
rs2.Fields.Appe nd "Case_or_Issue" , adVarChar, 50
rs2.Fields.Appe nd "Case_Numbe r", adInteger
rs2.Fields.Appe nd "Client", adInteger

If Me.Frame_1 = 1 Then 'then we are searching on Party Name
'now loop through rs1 and see if the instr() function gets a
match, if so, add to rs2
rs2.Open
For i = 0 To myRecordCount - 1
If InStr(rs1!Case_ or_Issue, myTerm) > 0 Then 'we have a
match
rs2.AddNew Array("Case_ID" , "Case_or_Issue" ,
"Case_Numbe r", "Client"), Array(rs1!Case_ ID, rs1!Case_or_Iss ue,
rs1!Case_Number , rs1!Client)
rs2.Update
End If

If rs1.EOF = False Then
rs1.MoveNext
End If

Next 'next record
ElseIf Me.Frame_1 = 2 Then 'then we are searching on case
number
ElseIf Me.Frame_1 = 3 Then 'then we are searching on case ID

End If

Set Me.Recordset = rs2
Me.Requery

rs2.Close
rs1.Close

rs1 has all of the same field names as rs2, but rs2 does not have all
of the same field names as rs1. Is that where my problem is? Can
someone tell me how to fix this so that the rs2 records display on my
form?

Thanks,

Jody Blau



Wow!
Where did that idea come from? Surely not from any standard Access
textbook? From a suggestion here? Or did you just let your imagination run
wild? You are mixing DAO and ADO recordsets, building up a 'virtual'
recordset which is not bound to any of your tables.
A more standard approach would be simply to update the form's recordsource
(not recordset). So this means you build up the SQL and assign it to the
recordsource:
strSQL="Select * from Case_List WHERE Case_or_Issue Like ""*" & strSearch &
"*"""
Me.RecordSource =strSQL
This assumes Case_or_Issue Like is a text field which won't contain quotes.
If it might, then you need to add a bit more code to double them up.

Feb 16 '06 #2
Thanks for the help,

I admit I am using a mix of examples and then spining them around in
my imagination.
I'm actually a lawyer by profession, rather than a programmer, so I
am learning this stuff for the first time, and on-the-fly.
So, I appreciate your help and I will definately incorporate your
suggestion!
Thanks,

Jody Blau

Feb 16 '06 #3

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

Similar topics

3
2079
by: Christopher Jeris | last post by:
Please help me understand the differences, in semantics, browser support and moral preferredness, between the following three methods of swapping content in and out of a page via JavaScript. I would also appreciate any general criticism you have to offer. I don't know yet how to write the degradation-path code for browsers that don't support the DOM methods I'm using, so there are some commented-out paths below. If the content...
22
6097
by: James Cane | last post by:
Here's an interesting problem that someone might have an answer to... Some time ago, I wrote a set of utility classes which wrap up the custom row source function needed to add arbitrary items to a combo or listbox. It all works nicely and allows me to do things such as sorting by clicking on column headings. Recently, all the machines here were upgraded to Access XP from 97 and I thought it might be time to take advantage of the new...
16
5720
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and got a nudge in the right direction from Mr. Kreft. I promised to provide details once working, so here it is. The code is shown below. My next step is to build this technique into my application. I'm hoping for substantial performance gain. ...
24
8495
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a workaround for lack of a way to define the ordinal position of a field (incrementing a counter variable), but it feels so primitive: dim Fld as Field dim rst1 as new adodb.recordset
0
2358
by: nachiket2k2 | last post by:
Hi, I am using VB 6.0, ADO 2.0 with MS Access 2000 Database. in a vb form, i need to fatch data from 3 different tables (ABC.MDB). it will be a tedious job if i create 3 connections with 3 recordsets. is it possible to do programming in such a way that we can use multiple recordsets with SAME connection? firing SQL statments one after the other and building recordsets. each recordset will contain different no. of records. if yes,...
4
2435
by: rdemyan via AccessMonster.com | last post by:
Can someone help me with creating code that will look for DAO recordsets in modules and then check to see if the recordset is also closed in the module. All of my recordsets are of the form rs* where * is a wildcard for letters after rs. Thanks. -- Message posted via AccessMonster.com
0
1071
by: JonC | last post by:
I am developong a database using acces 2003 and have got to a stage where I have a form with two levels of nested subforms. Recordsets are selected using a string of linked comboboxes and this is all working fine. The problem is that I need to be able to print these recordsets as a report and I can't figure out how to open a report on the recordset selected using the form. If anyone can help it would save me a lot of hair that I'm...
1
3733
by: sphinney | last post by:
As my Access form opens, I want it to find the names of the tables in the current Access database and populate a combobox with the table (recordset) names. Problem is, the CurrentDb.Recordsets object is empty even though I have two tables in the database. I'm using the code below, but the combobox remains empty. That's because CurrentDB.Recordsets is empty. Is this a bug with CurrentDb or have I done something dumb? Dim TBL As...
12
2238
convexcube
by: convexcube | last post by:
Hi Experts, I have a unbound form which records details of complaints. It also records what products are affected in the complaint. These are stored in a table named ComplaintProducts that has the fields: ComplaintProductsIndex (Autonumber), ComplaintIndex & ProductName. The product list is quite lengthy, so I have set up a separate form which opens when the Products Affected list box on the Complaints form is double clicked, containing a...
0
8726
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
8645
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
9214
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
8925
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
7810
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5903
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4404
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
4657
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3089
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

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.