944,098 Members | Top Members by Rank

Ad:
Feb 1st, 2006
0

Need help with my database

Expand Post »
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2.  
  3. Dim Pacdb As New ADODB.Connection
  4. Dim Pacrs As New ADODB.Recordset
  5. Dim Paccmd As New ADODB.Command
  6.  
  7. Pacdb.CursorLocation = adUseClient
  8. Pacdb.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Documents and Settings\Owner\My Documents\PruebaPropac\HistoriasClĂ­nicas.mdb;Mode=Read|Write"
  9. Pacdb.Open
  10.  
  11. With Paccmd
  12. .ActiveConnection = Pacdb
  13. .CommandText = "SELECT * FROM Pacientes ORDER BY Nombre;"
  14. .CommandType = adCmdText
  15. End With
  16.  
  17. With Pacrs
  18. .CursorType = adOpenStatic
  19. .CursorLocation = adUseClient
  20. .LockType = adLockOptimistic
  21. .Open Paccmd
  22. End With
Please help me, tell me what code I'm missing for the database to return each value in a predetermined text box.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yoshidex is offline Offline
21 posts
since Jun 2005
Feb 1st, 2006
0

Re: Need help with my database

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yoshidex is offline Offline
21 posts
since Jun 2005
Feb 3rd, 2006
0

Re: Need help with my database

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
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Manojsah is offline Offline
13 posts
since Aug 2005
Feb 3rd, 2006
0

Re: Need help with my database

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:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yoshidex is offline Offline
21 posts
since Jun 2005
Feb 3rd, 2006
0

Re: Need help with my database

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;
Pacrs.Open str, Pacdb, adOpenDynamic, adLockOptimistic 

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yoshidex is offline Offline
21 posts
since Jun 2005
Feb 4th, 2006
0

Re: Need help with my database

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
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Manojsah is offline Offline
13 posts
since Aug 2005
Feb 4th, 2006
0

Re: Need help with my database

Thx again man, I can say now that this thread is solved.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Yoshidex is offline Offline
21 posts
since Jun 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: progress bar problem in vb
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Task Schedular





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC