Hello there, is been a while since I last posted here, mostly because I didn't have the time I needed to program. But now, I reentered the exciting world in Visual Basic, 'cause I have a lot of time now and my mom wants me to make her a database :lol:
Anyway, I'm using VB 6.0 and I thought it was going to be easier than it's becomed. It all started when I tried to add a Search command button to the database the Data Form Object Wizard built. I searched through the internet and the forums and found out about SQL and ADO and read some tutorials on them, even the one that is posted at the beginning of the VB forum and decided to make one from scratch. But now, although my code seems right, it won't return me any records. I want the records to be input into Text Boxes. Here's the starting code I'm using in the Form_Load:

Private Sub Form_Load()

Dim Pacdb As New ADODB.Connection
Dim Pacrs As New ADODB.Recordset
Dim Paccmd As New ADODB.Command

Pacdb.CursorLocation = adUseClient
Pacdb.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Documents and Settings\Owner\My Documents\PruebaPropac\HistoriasClĂ­nicas.mdb;Mode=Read|Write"
Pacdb.Open

With Paccmd
  .ActiveConnection = Pacdb
  .CommandText = "SELECT * FROM Pacientes ORDER BY Nombre;"
  .CommandType = adCmdText
End With

With Pacrs
  .CursorType = adOpenStatic
  .CursorLocation = adUseClient
  .LockType = adLockOptimistic
  .Open Paccmd
End With

Please help me, tell me what code I'm missing for the database to return each value in a predetermined text box.

I forgot to ask if there was a way of doing this easier with the Data Form Wizard, and if so, how to add the search command.
Thx again XD

Hello,
I am also a new user , but i know the connectivity,
please try the code below ??

manojsah


Private Sub Form_Load()


Dim Pacdb As New ADODB.Connection
Dim Pacrs As New ADODB.Recordset
'Dim Paccmd As New ADODB.Command
Dim str As String


Pacdb.Open = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Documents and Settings\Owner\My Documents\PruebaPropac\HistoriasClĂ­nicas.mdb;Mode=Read|Write"
str = "SELECT * FROM Pacientes ORDER BY Nombre;"
Pacrs.Open str, Pacdb, adOpenDynamic, adLockOptimistic
Pacrs.MoveFirst
text1.Text = (Pacrs!Attribute_name)

End Sub


Bye
manojsah

Hey man, thank you very much it really worked, except that you don't need the "=" after Pacdb.Open or it won't work, but everything else was a lot of help. Anyway, be aware of this thread because I will post more here if I have more problems with my database. Thanks a lot. :mrgreen:

Man, I can get it. What am I doing wrong? Now I want to see the next records using a button, just to see if they're there, but it returns me an error of:

"Arguments are of the wrong type, are out of acceptable range or are in conflict with one another"

When I press the button. Then, if I press the Debug option, it highlights the following part of the buttons code:

Private Sub Command1_Click()
Dim str As String
Dim Pacrs As New ADODB.Recordset

str = "SELECT * FROM Pacientes ORDER BY Nombre;"

'This is what the debug option highlights;
[U]Pacrs.Open str, Pacdb, adOpenDynamic, adLockOptimistic[/U] 

If Not Pacrs.EOF Then
  Pacrs.MoveNext
End If

Pacrs.Close

End Sub

The rest of the code is already been post by manojsah. Can anyone tell me what did I do wrong?
Thanks in advance for the help you can provide.

Dear Friend,
Assume rs as your recordset now change the below code with your recordset variable
i.e pacrs
make one Command Button and make the changes in below code.

here (rs!agency_no)
agency_no is your attribute.........
Ok bye
Enjoy Programming
take care
Manoj


Private Sub Command1_Click()

rs.MoveNext
If rs.EOF Then
rs.MoveLast
MsgBox ("On Last record")
Else
rs.MoveNext
MsgBox(rs!agency_no)

End If


End Sub

This question has already been answered. Start a new discussion instead.