Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating and opening a recordset

Status
Not open for further replies.

Bohdii

Technical User
Aug 2, 2001
6
CA
Could someone please post an example of how to create and open a recordset with 4 variables?

thanks
 
Here is an example. I am not sure what you mean by "with 4 variables"

Dim rsMyRecordset as adodb.recordset
dim cnConnection as adodb.connection
Dim sSQL as string

set rsMyrecordset = createobject("adodb.recordset")
set cnConnection = createobject("adodb.connection")

cnconnection.connectionstring = "Provider=YourProvider;Data Source=YourServer;User Id=;password="
cnconnection.open

sSQL = "SELECT * FROM TABLE
WHERE FIELD='" & MyVariable & '""

rsMyRecodset.open ssql,cnconnection,adOpenForwardOnly, adLockReadOnly, adExecuteNoRecords And adCmdText


 
you mean a recordset with 4 columns?
a querydef with variables?
bluenote@uyuyuy.com
(excuse my english)
 
I'm not sure - novice. I want to create a spreadsheet in VB, I was given the following suggestion using the MSFlexGrid and I'm stuck at step 2:

----------

Step 1: Add a component Microsoft FlexGrid to your project and MSFlexGrid1 to your form

Step 2: Create and open a recordset rstAccess, must have at least 4 fields for this example

Step 3: Add a FlexGrid to your form, called MSFlexGrid1

Step 4: Add this code to your form, call it on load or with a command button

With MSFlexGrid1
.Clear
.Rows = 2
.Cols = 4
.FormatString = "One" & vbTab & "Two" & _
vbTab & "Three" & vbTab & "Four"
For intCount = 1 To rstAccess.RecordCount
.AddItem (rstAccess.Fields(0)) & vbTab & _
(rstAccess.Fields(1)) & vbTab & (rstAccess.Fields(2)) & _
vbTab & (rstAccess.Fields(3))
rstAccess.MoveNext
Next intCount
.ColWidth(0) = .Width / 4.1
.ColWidth(1) = .Width / 4.1
.ColWidth(2) = .Width / 4.1
.ColWidth(3) = .Width / 4.1
.RowHeight(1) = 40
End With

----------

Any help you could give would be appreciated.
 
You can use the example I posted. In your database, create a table with 4 fields. In the SQL statment just say:
sSQL = "SELECT * FROM YourTable"
When you reference your recordset in the example you posted:
"rstAccess.Fields(0)" would be the first field
"rstAccess.Fields(1)" would be the second field and so on
 
You can also use
Code:
rstAccess.Fields("fieldname") 
'or 
rstAccess!fieldname
to get the value of each field

::) bluenote@uyuyuy.com
(excuse my english)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top