-
May 16th, 2014, 12:05 AM
#1
Thread Starter
Lively Member
-
May 16th, 2014, 12:22 AM
#2
Re: Select Multiple Records in Access
The query you are showing should return all those records that match, assuming of course that is a text field.
Your image shows a lot of stuff that would not be returned by that query so not sure what you are doing.
-
May 16th, 2014, 12:27 AM
#3
Re: Select Multiple Records in Access
The code could be set out like
Code:
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Private Sub Form_Load()
Dim ConnectionString As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source= " & App.Path & "\Database.mdb"
cn.Open ConnectionString
rs.CursorLocation = adUseClient
End Sub
Private Sub Form_Terminate()
cn.Close
End Sub
Private Sub Command1_Click()
rs.Open "M_Test", cn, adOpenKeyset, adLockPessimistic, adCmdTable
ssql = "Select Test FROM M_Test where investigationNo = '" & Text17.Text & " '"
Set rs = cn.Execute(ssql)
MsgBox (rs.GetString)
End Sub
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 16th, 2014, 12:56 AM
#4
Thread Starter
Lively Member
Re: Select Multiple Records in Access
Thank You Mr.Nightwalker , It works great
But how can i add records(5 records) into flexgrid???
Thanks Again Sir..
-
May 16th, 2014, 01:06 AM
#5
Re: Select Multiple Records in Access
Can't read your code in the image, copy and paste the actual code rather than an image of it.
-
May 16th, 2014, 01:18 AM
#6
Thread Starter
Lively Member
Re: Select Multiple Records in Access
Code:
Private Sub Command3_Click()
Set rs = New ADODB.Recordset
rs.Open "M_Test", cn, adOpenKeyset, adLockPessimistic, adCmdTable
ssql = "Select Test FROM M_Test where investigationNo = '" & Text17.Text & " '"
Set rs = cn.Execute(ssql)
MSFlexGrid1.AddItem Label22.Caption & vbTab & (rs.GetString)
End Sub
It works..But All of the records assembled(combined) in one row in msflexgrid...
how can i get separate rows for each tests...
Thank you
-
May 16th, 2014, 01:22 AM
#7
Re: Select Multiple Records in Access
You would want to loop through the returned recordset
Code:
Do Until RS.EOF
' add the row to the grid using RS!Test rather than .Getstring
Rs.MoveNext
Loop
You also should not be using the RS.Open there as it is just a waste of time and space. You do nothing with it and then abandon it and create a new recordset with the same var. Leaving VB to deal with the orphaned recordset you opened using rs.open.
Last edited by DataMiser; May 16th, 2014 at 01:25 AM.
-
May 16th, 2014, 01:32 AM
#8
Thread Starter
Lively Member
Re: Select Multiple Records in Access
Ohh..... thank you Mr.Miser....
I forget it..
Thanks agian
-
May 16th, 2014, 03:04 AM
#9
Re: Select Multiple Records in Access
Originally Posted by DataMiser
You also should not be using the RS.Open there as it is just a waste of time and space. You do nothing with it and then abandon it and create a new recordset with the same var. Leaving VB to deal with the orphaned recordset you opened using rs.open.
It is interesting that it allows for the retrieval or updating of data despite opening the recordset.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 16th, 2014, 09:31 AM
#10
Re: Select Multiple Records in Access
Originally Posted by Nightwalker83
It is interesting that it allows for the retrieval or updating of data despite opening the recordset.
The SET statement creates a new recordset with the results of the execute. The other recordset is still there but rs no longer points to it.
Basically you end up with a chunk on memory allocated with data stuffed in it and no way to access it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|