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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to navigate records?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
0
0
I am using ADODC control to access the database, but I did not bind the controls in my form to the backend database. Therefore I have to manipulate data by writing codes for example, addnew, update, navigate. How can I write this kind of program? Do I need to create recordset in each event? if not, how can I do it?

I wrote this pieces of code for navigation, it did not work. Need help me to troubleshoot.

Thanks

Haijun
Private Sub cmdLeft_Click()
Dim strSelectDailycare As String
strSelectDailycare = "select * from tblDailycare where admitID = " & txtAdmissionID

Adodc6.CommandType = adCmdText
Adodc6.RecordSource = strSelectDailycare
Adodc6.Refresh

Print Adodc6.Recordset.RecordCount

If Adodc6.Recordset.AbsolutePosition = adPosEOF Then
Adodc6.Recordset.MoveLast
Else
Adodc6.Recordset.MoveNext
End If
End Sub
 
Hi,

These lines have to be called only once not each time you click the move record button. Put the lines in a form_load
event.

Dim strSelectDailycare As String

strSelectDailycare = "select * from tblDailycare where admitID = " & txtAdmissionID

Adodc6.CommandType = adCmdText
Adodc6.RecordSource = strSelectDailycare
Adodc6.Refresh

Have a good one!
BK
 
Hi BlackKnight:
I just tried your suggestion. When I put these lines of code into my form_load event, it did not work. because no value is assigned to txtAdmissionID fields. Any other ideas?

Haijun
 
what do u want to do exactly Haijun? u have added it to left click...i dont think this is what u want to do...
if u want to add records and stuff...add a command button...and u have to have a value for admissionID is ur searching on the basis of admissionID
 
I am sorry not to state my question clearly. What I want to do is to display records without binding the controls (textbox) to ADODC. I know is is easier to bind the controls to bound control. But I would like to control the record through coding. When "leftClick" button is clicked, recordset will goto previous record. There is also "rightclick" button, which will make recordset go to next when it is clicked. I do not know whether you understand my question.

Thanks

Haijun
 
ya i got u haijun...i think ur trying to display data in a textbox based on the value of admissionID given in some other textbox..is it what ur doing...if so then...this might help u...


private sub cmdLeft_Click()
Set connDailyCare = New adodb.Connection
connDailyCare.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Databasename.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"

strSelectDailycare = "select * from tblDailycare where admitID = " & "'" & trim(txtAdmissionID.text) & "'"

Set rsDailyCare = New adodb.Recordset
rsDailyCare.Open strSelectDailycare , connDailyCare, adOpenForwardOnly, adLockReadOnly

if rsDailyCare.recordcount>0 then
rsDailyCare.MoveNext
txtDailyCare.Text=rsDailyCare.Fields(0).value
endif

end sub

hope this helps
explain a little and i will definitely help u
praveen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top