Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How Do I Add A Field To An Open Recordset?


I have a microsoft access database that I am accessing
with an ADODB recordset. I want to add some fields to
this database table. The problem is that VB wont let me
use the fields.append method to add a field while the
recordset is open. If I append then open, my appended
fields do not get added.

Anyone know how to do this?

I also would like to create an entire new table in an
access database. Anyone know how to do this?


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Fill A Dbf Or Access Table Field With A Recordset Field
I need to fill out a dbf field with values from a recordset I get through a query.
The target dbf has a "variable" field which have to be filled with values from a recordset.
Any help will be appreciated.

I Need A Way To Update A Field Based On The Value Of Another Field In The Recordset
Basically, I have this form that allows you to take temporary records and place them in the permanent table, and assigns them a CertNo based on the last available CertNo. This is all works fine, but now there will be a Different CertNo depending on which certification you are. I need to be able to look up the last CertNo for each Cert type.

Below is the code that assigns the data to the query that the will hold the data.

Any ideas?

Private Sub cmdMigrate_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strCertNo As String
Dim strSQL As String
Dim strQueryName As String
Dim dbs As Database
Dim rst As Recordset

Set frm = Forms!frmMigration
Set ctl = frm!lstMultiSelect
strSQL = "SELECT * FROM [qryExamPassed] WHERE [qryExamPassed].[SSAN]='"
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & "' Or [qryExamPassed].[SSAN]='"
Next varItem
strSQL = Left$(strSQL, Len(strSQL) - 28)
strQueryName = "qryExamMigrate"
CreateCertQuery strSQL, strQueryName
Set dbs = CurrentDb
Set rst = OpenForSeek("tblCertification")
rst.Index = "CertNum"
strCertNo = rst!CERT_NO

Set rst = dbs.OpenRecordset("qryExamMigrate")
strCertNo = LTrim(Str(Val(strCertNo) + 1))
rst("TEMP_CERTNO") = strCertNo
Loop Until rst.EOF

DoCmd.OpenForm "frmMigration2"
End Sub

Recordset.Open Or Set Recordset = Connection.Execute()?
Hello to all! Is there any difference with Recordset.Open and Set Recordset = Connection.Execute in executing an SQL query? I just want to know because users of my program sometimes getting the [-2147467259] Timeout expired error. A friend of mine said that Recorset.Open is the correct way in executing an SQL query rather than using Set Recordset = Connection.Execute.

Here's how I code...

Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset

Con.ConnectionString = "Initial Catalog=;Data Source="
Con.CursorLocation = adUseClient

Set Rs = Con.Execute("SQL Query")

-- Hope you understand what I'm saying. I'm quite poor in explaining something in english. Thanks in advance

How Do You Check To See If A Recordset Is Closed When Trying To Open A New Recordset?
I have some code that contains so many recordset open and closes now that I am starting to confuse myself. So I was wondering if I can somehow check to see if a recordset is open already before openign the recordset because when I try my code some times it will work but I have so many ways of opening and closing recordsets that soemtimes it is still open when I want to open it again, cause run-time 3705 error where it tells me I cannot already open my recordset. The thing is the program shuts down right away so I cannot really edit the code without having to load it again.

My 1 line of code below:

rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly

now I want to do soemthign like this:

if rschild2.close is true then
     rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly
    rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly
end if

Any help would be appreciated. Thanks.

Edited by - jjoseph on 11/4/2005 5:52:16 PM

Open DAO Recordset Without Using A Recordset Object
In order to use a certain password-protected ODBC connection, I first run a Pass-Through query against one of the tables.  Once the Pass-Through query is run I can use linked tables in my Access db without concerning myself with the password protection.

I've set up the Pass-Through query (we'll call it ConnectionQ) in my Access db and call it like this:

dbDBase.OpenRecordset "ConnectionQ"

Where does that recordset go?  Do I need to worry about a recordset object that might be floating around in my stack space?  or does it get created and destroyed all in one operation?  It is a SELECT query as I'm unable to run any action queries against the ODBC db.

Getting The Field Name In A Recordset
Hi all,

I am looping through a recordset in SQL Server and I am trying to extract the field name and store it in a string. I will then do a case statement based on that value and assign a value to another string like so.


Public Function InsertChanges(oConn As ADODB.Connection, oRec As ADODB.Recordset, _
strOldValue As String, strNewValue As String)
'InsertChanges compares the values of each pair's fields. For each difference in
'the fields, a record will be written to the db.

If strOldValue <> strNewValue Then

'Declare local field variables
Dim intRecID As Long
Dim strEditDate As String
Dim strAcctName As String
Dim strAcctNo As String
Dim strField As String
Dim strOldValue As String
Dim strNewValue As String

Dim sFieldName as string

' Here I want to get the field name and store it......

'Set values for sFieldName

Select Case sFieldName
Case "RecID"
strField = "Record ID"
Case "EditDate"
strField = "Edit Date"

'and so on........

End Select

any help would be cool


Recordset Field: Key?
Does the fields-element of the a recordset has a property which contains information wether this field is a key or not?

Tried to search on it, but never found....


How To Get Recordset Field Name ?
Can I still get the recordset information without knowing the name of
the field?
I'd like to be able to write out everything in the database including
field name without knowing the name of the field.
Is it possible?

Thanks for your help!

Recordset Field Name
Hi all ....

Is there is anyway to put a variable in the recordset fields name !?

Well my program reads set of text files & add columns to the database with the name of these text files !!! the files name r not constant !!

so i dont know the fileds name here!!

i need a code which do this 4 me

' ADO1.Recordset.Fields(" & fname & ") = Counter(i)

where fname is a string asigne to the file name

is there is anyway to do it ...

hope yes

& hope that someone can help me!!
i really need to know this

thanx in advance,

To Get Field Value From Recordset
any i know how? instead or use this



How To Tell A Field In A Recordset Is Empty
Ok I am implementing a database application. I am working with MaskEdBox this is how i have it working, one form comes up and the user types in the name they want to search for, then another form pops up with the matches in a listbox, then u click on the name u want and it jumps back to the orignal form, but the problem is i need to know how to tell in code if a particular field in recordset is empty. Like for instance
I am searching for Jimmy I find his name on the list and i click on his name, how can i tell before populating the form with his info if the recordset has nothing for his address or so on. Any help would be greatly appreciated

here is what i have

If rs!Workphone = "" Then
mskphone.Mask = mskphone.Format
mskphone.Text = rs!Workphone
End If

Insert Field Into An Ado Recordset

Just a quick question - an sql command brings values from an access table and populates an Ado recordset. Can I insert a new field into this recordset that doesnt belong to any table (and doesnt need to contain a value)?

Eventually the Ado recordset will be passed into an Excel spreadsheet and I want this field to be passed with it also. For example the new field I want would be called Record required so that the user can open Excel (populated bu Ado results) and place and X or Y against each record that he/she requires.

I looked at adding the new column in my ado to excel procedure but it got a bit messy!!

Fairly new to VB6 so any help would be appreciated.


Recordset Field Type
How do I find the type of a field of a recordset. Integer or string etc.

I tried using the type property, and got a long.

ADO Recordset Field Name Problem
My problem is ADO couldn't find the object in the collection..
easiest way to explain it is a example:

I have a database table with a Field Name "Serial No"

Okay.. I do the adoConnection to the database,
and the recordset (adoRS_SerialNo) is opened to the table.

Now I want to get the value form this field..
Normally it would be like
adoRS_SerialNo!{Field Name}

My problem is how do I put a field name of "Serial No" into it.

ie adoRS_SerialNo!Serial No <===== ERROR

Thanks for the help.

How To Ask A For A Date In A Recordsetīs Field ??

I tried this in an Access 2002 Modul, to ask for a special date, in a special ADODB.Recordset:


For i = 0 To rstPAM.RecordCount - 1

WV = Format(rstPAM!Wiedervorlage, "")

If WV = '01.01.2001' Then

rstPAM!Wiedervorlage = Null

End If


But the If - clasue is always wrong. I donīt know what to do !! I couldnīt find anything in MSDN or the Forum.

Please help

Recordset.Field Count

I was wondering while I get two different outputs of my recorset count field on the datagrid depending on using order by in my SQL statement?

I basically want to diplay the numbers from 1 to whatever number of records is displayed on my data grid.

If I don't use order by in my SQL statement it works fine and say there are 4records it will number all 4 instead of giving them numbers from 1 to 4.

If I don't use order by it works fine and gives them number like 1,2,3,4

Any ideas?

Assign New Value To Field Of Recordset
i m fatching values from recordset.and checking a particular field value if its blank then assigning a new value but it is not assigning a new value to a field.what i m missing.or its a wrong way.

If (rstTemp("RecipientID") = "") Then
rstTemp("RecipientID").Value = tsIDocumentMetaData.mdNoDocumentRecipient
End If

Calling A Field From A Recordset
hi all

Another quick question....

I have a selection into recordset oRS

VB Code:
strsql = "Select Count(CustomerPO) From stgEDI_Import"strsql = strsql & " WHERE ImportStatus = 0 and SessionKey = " & SessionKey '  

how would i represent the resulting query in oRS?

I have tried oRS("Count(CustomerPO)") and oRS("CustomerPO") and both give me an error "Item cannot be found in the collection......"

So what would be the correct syntax for oRS?

Update One Field Of Recordset
Hello all,

Why can't I update only one field of my recordset? My rs1 have 10 fields.

My code so far:

rs1.Filter = adFilterNone
rs1.Filter = "NID like " & id_service
If rs1.RecordCount = 1 Then
rs1.Fields!id_Client = 2
End If

when updating ( rs1.update ) a run-time error pops up

Appending To A Field Name Of A Recordset
The scenario:

I have day1....through to day14 as fields in my database

when i retrieve the fields from an access database I want to create a loop where i can check each field. To do this I wish to increment the field Day by one each time each time i check them. ie have it as "!Day + variable" where i append the variable to create the field of that recordset.

The alternative is to copy the code and paste it a number of times and check each one by hard coding this but i know that the above method must be better practice.

dim x as integer
x = 1

Do While grsSystem.EOF <> True

Text1.Text = !Day(x)

If !Day(x + 1) <> !Day + '"x"' Then

Text2.Text = !Day(x + 1)

lblDays.Caption = "Day 1 - + 'x'"

End If




Recordset.Field Count
I have the following code to display message box decided by the recordset field count however it does display one only... Can anyone figure out why?


Private Sub Form_Load()
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset

Set myConnection = New ADODB.Connection

myConnection.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=BIBLIO.mdb"


Set myRecordset = New ADODB.Recordset

myRecordset.Open "select Name from Publishers", myConnection, adOpenStatic, adLockReadOnly

For i = 0 To myRecordset.Fields.Count - 1

MsgBox myRecordset.Fields(i)

Next i


Set myRecordset = Nothing


Set myConnection = Nothing

End Sub

Recordset And Referencing A Field
I am using an ADO recordset. Now there are several ways to reference a field within the recordset. Is there any difference in the way you do it? Is one way better than the other?

VB Code:
rs.fields("Field 1")rs("Field 1") rs(0) 'I think this way would be the fastest since it doesn't'have to do any comparison of the names in the fields. It knows'to go straight to the first field in the recordset 'there is one more way using the ! but I forget the syntax  

I was just wondering if any method is better.

Recordset Field Count
This is quite the odd problem I've run into here. I've got a textfile with 17 columns, delimitted by 10 spaces. When I check the Field Count, ie rs.Fields.Count it retuns 17, which is expected. However, if I try to access Fields(1).Value, I get an "Improver use of null" error. I get and entire row when I enter Fields(0).Value. So I guess my question is, how are the fields indexed? I mean, it knows that I have 17 columns, but doesn't know the first item in a column.

ADO Recordset Field Names
If I query a database using ADO 2.6 with the statement "Select * from [tbl_Users]", is there a way to find all the column names that the recordset returns? For example, is there a way to find that the columns 'FName', 'LName', 'UserID', are the columns that are returned from the database?

How To Get Field Length From A Recordset?
I need to find out the field size of a particular field
from a recordset, I used rs.fields(x).fieldsize, it gives
me error. I use rs.fields(x).size, it gives me wrong answer.

Please help to tell me how I can do it.

ps. How about if the db field is created with Decimal(5, 0),
how I can red the field length?


Writing To Available Recordset Field
Hello all

Can anyone please clue me in on an easy way to identify which tablerecordset field is null (vacant) so that my code can write to that fielddynamically. Here is my dilemna in a nutshell.

I have a table with a number of fields named Item1, Item2, Item3, Item4etc...
I need to be able to determine which fields are already populated andsave data to the next available field of this type.

I've bound the table to a data control and am using therecordset.addnew, edit and updaterecord commands to handle data saves. Itried setting a variable like this but it isn't supported .......datacontrol.recordset.Item(i) as opposed todatacontrol.recordset.Item1, datacontrol.recordset.Item2 etc...

I've got to be overlooking something.
How can I accomplish this task simply?


Get String From Recordset Field
We are upgrading our system to server2003 and have to change the method used for email.
We get a recordset from a database as follows:

toEmail = recordset("email")

When we try to send mail with this it errors out. It seems that a field object is being moved to the toEmail variable.

I have tried:
toEmail = recordset("email").value

This causes the same error.

Any ideas, help

Recordset Field Question
I know you can use the following :

strExample = datTest.recordset.fields(1)

The problem with that is that if I add to the database the fields(1) or fields(27), etc. may change as the table grows/shrinks.
Can you refrence a field by its name? Something like fields(lastname)?
The field names are not likely to change even if the table grows.



How To: Update A Field's Value In A One-to-many Recordset
i am currently working on an application which was designed by the company's previous programmer. the design seems not that good because there are data that are both found in the master and in the detail section of a master/detail recordset. And, re-designing the database structure will seem to take a long time, so its not an option as of this time.

to synchcronize the data, i want to reflect the changes in the field belonged to the one-side, into the corresponding field in the many-side. This process will be done in the background so i'm using the recordset object and execute a query such as this:

strQuery = "UPDATE tbl1 SET fld3 = -1 WHERE fld1 = " _
& "(SELECT fld1 FROM tbl2 WHERE fld3 = -1)"

objComm.Execute lngRecs

this works when there is only 1 record in the many-side of the table but will generate an error when otherwise. The error no. and description is as below:

2147467259: (ODBC Microsoft Access Driver) At most one record can be returned by this subquery.

How will then i should write the SQL statement to achieve the purpose?


How To Sort The Recordset By Field
I need some direction.  I have a DAO connection to an Access database where I get data.  Each field in the Access database is displayed separately in a textbox in my program.  I would like to sort the main field name (called "Name") in ascending order.  Currently is doesn't do this.  How is this done?

I was thinking that "data1.recordset.sort" would provide an option for the field name with an option to select either ASC or DESC, but I can't find this.  Where should I go?

Compare Recordset Field Value
Hi, this is my second post. Hope someone can give me an idea on how to do it.

I want to compare the first value with the next value until EOF.
See for example if I have this first field value of S0001N10_XX_2 (field value has 10 char)
- Compare this value with the second value, third, fourth until EOF and then it loop incrementing its row.

By the way I am using Access97 DB.

Edited by - cglccb on 3/2/2005 6:02:25 PM

Dynamic Recordset Field Name?????
hi, i got a real problem here!

i'm building a stats app and got thousands of thousands number in it

fields name are : int1 , int 2 , int3 to int20

is there any way i could change this code :

If (rs!int1 < 5) Then
                            c(0) = c(0) + 1
                        ElseIf ((rs!int1 > 5) And (rs!int1 < 10)) Then
                            c(1) = c(1) + 1
                        ElseIf ((rs!int1 > 10) And (rs!int1 < 15)) Then
                            c(2) = c(2) + 1
                        ElseIf ((rs!int1 > 15) And (rs!int1 < 20)) Then
                            c(3) = c(3) + 1
                        ElseIf ((rs!int1 > 20) And (rs!int1 < 25)) Then
                            c(4) = c(4) + 1
                        ElseIf ((rs!int1 > 25) And (rs!int1 < 30)) Then
                            c(5) = c(5) + 1
                        ElseIf ((rs!int1 > 30) And (rs!int1 < 35)) Then
                            c(6) = c(6) + 1
                        ElseIf ((rs!int1 > 35) And (rs!int1 < 40)) Then
                            c(7) = c(7) + 1
                        ElseIf ((rs!int1 > 40) And (rs!int1 < 45)) Then
                            c(8) = c(8) + 1
                        ElseIf ((rs!int1 > 45) And (rs!int1 < 50)) Then
                            c(9) = c(9) + 1
                        ElseIf ((rs!int1 > 50) And (rs!int1 < 55)) Then
                            c(10) = c(10) + 1
                        ElseIf ((rs!int1 > 55) And (rs!int1 < 60)) Then
                            c(11) = c(11) + 1
                        ElseIf ((rs!int1 > 60) And (rs!int1 < 65)) Then
                            c(12) = c(12) + 1
                        ElseIf ((rs!int1 > 65) And (rs!int1 < 70)) Then
                            c(13) = c(13) + 1
                        End If

into a FOR loop to parse every 20 fields ???
because like this, its pretty slow

any suggestions are MORE than welcome


°¡!°[Episode Hard Coding]°¡!°

Null Field In Recordset
If rs1("fld1") contains Null then

    str1 = rs1("fld1")

causes an error message but

    str1 = str1 & rs1("fld1")

seems to work. Why?


Recordset Field From Array
Hi I have a function i'm trying to get working so i can populate a word form. I've got a lot of fields so i want to use an array of fieldnames:
Function exportToWord()
    Dim db As DAO.Recordset
    Dim rs As DAO.Recordset
    Dim sql As String
    Dim fields As Variant

    sql = "SELECT * FROM qry_app WHERE student_id = " & Me.txt_student_id.Value & ";"
    Set rs = CurrentDb.OpenRecordset(sql)
    'Set objWord = CreateObject("Word.Application")
    'objWord.Documents.Add "export"
    'objWord.Visible = True
    fields = Array("surname", "firstnames", "student_reg", "gtcs_reg", "address_01", "address_02", "address_03", "town_city", "postcode", "degree", "award_title", "award_date", "sector", "age", "prog_duration", "date_attended", "officer", "position", "date", " comm_ku", "comm_sa", "comm_vp", "comm_ts", "prior_ku", "prior_sa", "prior_vp", "statement", "prof_dev")

    For i = 1 To UBound(fields)
    'ifield = Right(fields(i), Len(fields(i)) - 5)
    'MsgBox (rs.fields(fields(i)))
        If objWord.ActiveDocument.Bookmarks.Exists(fields(i)) = True And Not IsNull(rs.fields(fields(i))) Then '**Having problems here**
            objWord.ActiveDocument.Bookmarks(fields(i)).Range.Text = rs.fields(fields(i))
        End If
End Function

Edited by - Geof on 3/21/2007 4:12:30 AM

Getting A Field From A Recordset (should Be Easy)
How do i do something like this:
Dim Datab As ADODB.Connection
Dim rs As ADODB.Recordset
Dim counter As Long

... (some code here)

Set rs = New ADODB.Recordset
rs.Open "Select max(number)+1 from [COURRIER IMPORTED]", Datab

Now how do i get the value "max(number)+1" into 'Counter'???

Index A Field In Ado Recordset
If i want to index a field in a recordset, how can i do it.
I tried using OPTIMIZE property of the recordset object, but it doesn't shows any difference between a normal recordset and a recordset with it's OPTIMIZE property set to true. Also i used the SUPPORTS property of the rs(recordset), but i think ADO does not support it or there is some other prob.

Interate A Field In A Recordset . .
Can you use a For Each loop instead with a recordset, or would you first have to copy the fields into an array or collection?

If not, For each [what] IN [what]?

for intRecord = 1 to rsLocations.RecordCount
Debug.print rsLocations!LocID
If rsLocations.EOF then Exit for

Thanks for any response,

The Data Of A Field In A Recordset
I need the data in the field "name" in a recordset that I have made. And I miserably faild to get it.

help, thanx, love.

I Can't Assign A Value To Recordset Field ?
Hi All !

Please, give me advice.
I transferred my database from Access 2000 to SQL Server 2000. I work with it from VB application. With Access there was fine.
But now I open recordset (disconnected, adUseClient, adOpenStatic, adLockBatchOptimistic)
with such SQL:

select 0 AS num0, f1,f2,... from tTable,
where f1, f2..- fields of table tTable,
num0 doesn't belong to tTable

and then I need in such operator in VB-code:
ors!Num0 = 1
But this operator leads to "Multiple-step operation generated errors..."
I tested the attributes of the field Num0 and saw it's not updatable. Why ? Another fields are updatable. Why does
the same field from Access updatable but from SQLServer- no?
What can I do for doing Num0 updatable ? I need this first additional field (num0) in which I create ordinal numbers and I can't use for this any field from the table because they are not ordinal.

Help With Recordset Field Names And Writeline
I'm modifying a program that another developer wrote. An option in the program lets the user send the results to a text file. The issue is that the field names are not being included in the file so I have to add them. I'm not sure how to do this. The code for the sending the recordset to text file is:

txtFile.Write (rsPass.GetString(adClipString, TT, vbTab, _
vbCrLf, ""))

I was thinking that adding a txtFile.WriteLine with the rsPass field names would work, but I'm not sure how to do that. There are three options total (tab delimited, comma delimited, semicolon delimited). The line of code above is for the tab delimited file. Any help would rock.

Querying Recordset Field Items

I'm trying to do some integration between a word form and an access database, most of it is simple enough, but in order to enter purchase order data in to the database i need to enter header information (supplier details etc) and line item records.

I need to acquire the primary key of the record just inserted (using an INSERT INTO statement), so am using the @@identity function, i can return this as a recordset, but then when trying to work with the recordset using the code:

strSQL = "select @@identity"
Set rs = cnn.Execute(strSQL)
reqid = rs.Fields.Item(1).Value

i get the error "<Item cannot be found in the collection corresponding to the requested name or ordinal.>"

I've tried many different ways of getting the rs.Fields function to correctly show what i want, all without success.

The odd thing is that the rs can be viewed in the debug window and shows the details correctly, it just can't query them programmatically.

Any help really appreciated as i've been racking my brain on this and now have a headache.

Once I Have Opened A Recordset, How Can I Check If There Is A Field With A Value?
Hello, i would like to open up a recordset that will open all jobs for a certain user. Like this

UserID = txtLoginUserID.Text
Set rs = New ADODB.Recordset
strSQL = "SELECT tblJOBmain.ID, tblJOBmain.EmployeeID, tblJOBmain.Stage FROM tblJOBmain Where EmployeeID = " & Val(UserID)
rs.Open strSQL, cn, adOpenKeyset, adLockReadOnly, adCmdText

Now, i would like to perform a check for the stages within that recordset.
so in non VB code i would like to do this:

If there is > 1 record with stage 1 then
msgbox "serious error"
If there is 1 record with stage 1 then
open up form1

If there is > 1 record with stage 2 then
msgbox "serious error"
If there is 1 record with stage 2 then
open up form2

If there is > 1 record with stage 3 then
msgbox "serious error"
If there is 1 record with stage 3 then
open up form3

I really really really dont want to have to open up a new record set for each stage. Because this will be really really slow. I am looking to make this check as fast as possible!
Does anyone have any idea how i can do this?

this is a shortened version of my table structure:

Job number

Generic Field Call In A Recordset
Hi everybody !

A liitle question for you all : how can I get the field value of a recordset (ADO) without having to name it or to now the exact position ? For exemple, you have :
strField = rsTest!NAME_OF_THE_FIELD

I would like to be able to use a variable instead of the proper name. Can I do that ?

Binding A Text Box To A Recordset Field
How do I bind a text box, or datagrid, etc to a recordset?

Whom shall I fear?

Accessing Recordset Field Like An Array
I have a VB book that says you can do this. If you have a recordset called rs supposedly you can do . . .


and get at the 2nd record in the recordset. But Ive tried that on my own project and it wont work. Here's my code:

Public Function Median(numRecords As Integer, CityPop As ADODB.Recordset) As Double

'If numNumbers is odd
If Not (numRecords Mod 2 = 0) Then
Dim OddMiddle As Integer
OddMiddle = Int(numRecords / 2)
Median = CityPop.Fields(OddMiddle) ' get error here
' If numNumbers is even
Dim EvenMiddle As Integer
EvenMiddle = (((numRecords / 2) - 1) + (numRecords / 2)) / 2 ' get same error here when I block out above code
Median = CityPop.Fields(EvenMiddle)
End If

End Function
But I get an error at the
"Median = CityPop.Fields(OddMiddle)"
line that says, "Run-time Error 3265: Item cannot be found in the collection corresponding to the requested name or ordinal. " That particular error is not in my help files.

Anyone know how to get at a specific record (like in an array) in a recordset?

Is It Possible To Check If A Field Exists In A Recordset?
basically... i won't know until runtime if a field im trying to access exists or not.. but the problem is that of course if i try and access a field in a recodset that doesn't exist i get an error.

so can i do something like if (record.fields(name)) then.. i know this won't work but i'm lookin for something similar that does work

ADODC - Find Recordset WHERE Field(0)=X
HI, here is my problem:

I have 2 adodc objects, each on a different form in the same application. Each of the adodc objects gets data from the same table in the same asccess database, but one selects all records, while the other has a WHERE condition. Each adodc has a databound grid associated with it. Let's call them grid1 and grid2.

So far everything works beautifully.

What I need to do now is the following:

when the user selects a recordset (by moving the arrow) in grid1 and then clicks a certain button, I want the same recordset (the one with the same primary key) to be selected in my grid2 automatically. It may help you to know that the primary key is a text field called Title.

I have tried something like this (but it didn't work):

Dim CurrentTitle As String
CurrentTitle = form1.adodc1.Recordset.Fields(0)
form2.adodc1.Recordset.Find CurrentTitle

Please help me, ANIA

PS. I am attaching code just in case anyone cares to look at it.

Adding A Field To The Begining Of A Recordset
Is there anyway of adding a field to the beginning of a ADODB recordset which is already populated? I would rather not changed the stored procedure which creates the recordset or have to create a new stored procedure. I don't think rs.Fields.Append can do this, can it?



To Select Last Recordset From The Table Field
in my application i have a counter which i put in the database whenever the application is launched it has to start from the next value of the counter

for example, if the application is runing now and i m entering counter will keep increasing like 1,2,3,4,...if the application is stopped at counter = 15 then when next time it is lauched it has to start from 16...

to do this i m using following simple way...

While Not adorecordset_recevoi.EOF
strnum= adorecordset_recevoi.Fields("numero")

m = strnum

so in above code m will always have the latest value of the strnum....

this works good without errors....but i know this is not a good way to do this.....this is just a simple logic....

so i want to know whether this can crash at anytime and i should use any other method..(pls suggest one)....or i can go along with this...

this can be a silly question as my other questions on this board...but believe me i dont hve any experiance of vb and i m totally new person to this programming field as well...

thanx for any and all support...

Copyright Đ 2005-08, All rights reserved