Question about Microsoft Compilers & Programming Tools

1 Answer

Vb 6.0 ado connection without ado control moving next record

Here is my code

nothing is happen when i am clicking
or some times only one record is moved for move next

Private Sub cmdnext_Click()
Dim st As String
Dim que As String
Dim con As ADODB.Connection
Dim REC As ADODB.Recordset
st = "provider=microsoft.jet.oledb.4.0;Data source=" + App.Path + "db1.mdb"
Set con = New ADODB.Connection

With con
.ConnectionString = st
.Open
End With
que = "select * from class_add where class='" + cmbedit.Text + "'"
Set REC = New ADODB.Recordset
REC.Open que, con, adOpenDynamic, adLockReadOnly



REC.MoveNext
If Not REC.BOF Then REC.MoveNext

txtclass.Text = REC("class")
txtteacher.Text = REC("claasteacher")
txtleader.Text = REC("leader")
totstd.Text = REC("totstd")
txtsubj.Text = REC("no_subj")
txtroom.Text = REC("room_no")

End If
End Sub
thank you for spending your time

Posted by on

1 Answer

  • Level 2:

    An expert who has achieved level 2 by getting 100 points

    MVP:

    An expert that got 5 achievements.

    Novelist:

    An expert who has written 50 answers of more than 400 characters.

    Scholar:

    An expert who has written 20 answers of more than 400 characters.

  • Expert
  • 160 Answers

I see 2 problems with your code.

1) Each time you call cmdnext_Click, you're reopening the database. Each time you do that, you start at the beginning of the file. You need to have the database opened once, somewhere else in your program. Be sure that the record set is visible from this sub.

2) In order to use the "Next" function, you need a loop like this

'test for no records
IF REC.BOF and REC.EOF then
msgbox "No Records Found"
exit sub
end if

IF NOT REC.EOF then
REC.MoveNext
(display your fields)
END IF


Again, this will only work if your database is opened outside of the cmdNext_Click routine.

Posted on Jul 16, 2008

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How to connect visual basic program book title to access without ado?


what exactly are you trying to do
you can use ado,ado.net or use the entire routine in programming

write like

dim con as connection
dim rec as new recordset

rec = con.open(<<<access provider library>>>,<<<mode>>>,<<<password if any>>>)

..
...
...

your logic
...
..
con.close

just search for access library

Feb 27, 2011 | Microsoft Mlf Visual Studio Enterprise...

1 Answer

Example sorurce code for database


Hello my friend try this code: This code is design for Visual Basic 6.0
Function for Connection and recordset string.  '========Connection String====== Public Sub connection(ByRef dConnection As ADODB.connection, ByVal dLocation As String)     dConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dLocation & ";Persist Security Info=False;" End Sub '======End of Connection String======
'=======Recordset String=========== Public Sub recordset(ByRef sRecordset As ADODB.recordset, ByRef sConnection As ADODB.connection, ByVal sSQl As String) With sRecordset .CursorLocation = adUseClient .Open sSQl, sConnection, adOpenKeyset, adLockOptimistic End With End Sub '======End Recordset String========
How to apply the above function? Application:
'====== Command Save Button======== Private Sub cmdsave_Click() Dim cn3 As New ADODB.connection Dim rs3 As New ADODB.recordset
Call connection(cn3, App.Path & "\CASGC.mdb") Call recordset(rs3, cn3, "Select * from Debtor_Creditor_Account") Set dtglobal.DataSource = rs3.DataSource   
With rs3   .AddNew   .Fields("Code") = txtCode.Text   .Fields("Description") = txtDescription.Text   .Fields("Tag") = cbotag.Text   .Update   .Requery    End With   MsgBox "New Account has been Added", vbInformation   Set cn3 = Nothing Set rs3 = Nothing
End Sub '=======end of Command Save button=====
The advantage of using this code is setting your database connection is you have a reliable connection towards your database where ever you place your database you can you don't to remount you databse connection control. Also you are no longer need to use a ADO control or DAO control just copy the function and paste it in your coding area and call the function and you have now a working database and recordset connection string. 

For more details regarding how to apply this code just email me at this address: geo_jonas@yahoo.com to get more codes. thanks.. Please rate this Solution.

Jul 08, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

Looking for the code of "print"


You will be using the "Print # Statement" (see the VB Help file for full details). You may also want to check out the printer dialog control to allow your users to select a printer to print to.

Apr 24, 2009 | BDG Publishing Visual Basic Source Code...

1 Answer

Convert mdb to text files with vb 6.0 code


You will need to open the file using ADO and read the data into a recordset. Then loop through the rows and write them to a text file and use concatenation to format the rows in the text file as needed (CSV, tab delimited, whatever you need). Remember to add a vbCrLf after each row!

Apr 10, 2009 | LEAD Technologies Compilers & Programming...

2 Answers

VB 6.0 ROUNDING A NUMBER


Use the Math.Round() function. It takes two arguments, the first is your number or a variable holding your number and the second is the number of decimal places. This will only round to fractions of a whole number though and you need to round to the nearest 10. So divide your number by 10 before you round to shift the decimal place once to the left and multiply by 10 again afterwards to shift it back again.

answer = Math.Round(32.1 / 10, 0) * 10

Apr 02, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

How to access data from ms access with buffer in class code with vb application


Use ADO and create a connection string for a Jet file (version matters here when creating the string). Then use ADO commands and return recordsets to buffer your data.

Mar 26, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

Microsoft Access query in VB


first you need to create a record set to do this, after creating a record set RS1. please follow the code below:
Update the code as per your requirement.
Rs1.Open "Select * from table_name where UserName = '" & UName & "'", Cn1, adOpenDynamic, adLockOptimistic

Mar 14, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

Book mark property of recordset (ado)


The bookmark property of a recordset lets you store and retrieve the location of a record in a variable so that you can move directly to it in your recordset without having to use a query to extract that record. Like you can just move forward a record and back a record, or move to the first or last records without a quesry statement, you can move to the bookmarked record directly in code.

Here's a good VB example that compares the bookmakr property to the movefirst and movelast properties. This should answer your question, and please rate my answer.

'BeginBOFVB 'To integrate this code 'replace the data source and initial catalog values 'in the connection string Public Sub Main() On Error GoTo ErrorHandler 'recordset and connection variables Dim Cnxn As ADODB.Connection Dim rstPublishers As ADODB.Recordset Dim strCnxn As String Dim strSQLPubs As String 'record variables Dim strMessage As String Dim intCommand As Integer Dim varBookmark As Variant ' open connection Set Cnxn = New ADODB.Connection strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _ "Initial Catalog='Pubs';Integrated Security='SSPI';" Cnxn.Open strCnxn ' Open recordset and use client cursor ' to enable AbsolutePosition property Set rstPublishers = New ADODB.Recordset strSQLPubs = "SELECT pub_id, pub_name FROM publishers ORDER BY pub_name" rstPublishers.Open strSQLPubs, strCnxn, adUseClient, adOpenStatic, adCmdText rstPublishers.MoveFirst Do Until rstPublishers.EOF ' Display information about current record ' and get user input strMessage = "Publisher: " & rstPublishers!pub_name & _ vbCr & "(record " & rstPublishers.AbsolutePosition & _ " of " & rstPublishers.RecordCount & ")" & vbCr & vbCr & _ "Enter command:" & vbCr & _ "[1 - next / 2 - previous /" & vbCr & _ "3 - set bookmark / 4 - go to bookmark]" intCommand = Val(InputBox(strMessage)) ' Check user input Select Case intCommand Case 1 ' Move forward trapping for EOF rstPublishers.MoveNext If rstPublishers.EOF Then MsgBox "Moving past the last record." & _ vbCr & "Try again." rstPublishers.MoveLast End If Case 2 ' Move backward trapping for BOF rstPublishers.MovePrevious If rstPublishers.BOF Then MsgBox "Moving past the first record." & _ vbCr & "Try again." rstPublishers.MoveFirst End If Case 3 ' Store the bookmark of the current record varBookmark = rstPublishers.Bookmark Case 4 ' Go to the record indicated by the stored bookmark If IsEmpty(varBookmark) Then MsgBox "No Bookmark set!" Else rstPublishers.Bookmark = varBookmark End If Case Else Exit Do End Select Loop ' clean up rstPublishers.Close Cnxn.Close Set rstPublishers = Nothing Set Cnxn = Nothing Exit Sub ErrorHandler: ' clean up If Not rstPublishers Is Nothing Then If rstPublishers.State = adStateOpen Then rstPublishers.Close End If Set rstPublishers = Nothing If Not Cnxn Is Nothing Then If Cnxn.State = adStateOpen Then Cnxn.Close End If Set Cnxn = Nothing If Err <> 0 Then MsgBox Err.Source & "-->" & Err.Description, , "Error" End If End Sub 'EndBOFVB

Jan 07, 2009 | Microsoft Visual Basic 6.0 for PC

Not finding what you are looking for?
Compilers & Programming Tools Logo

Related Topics:

1,181 people viewed this question

Ask a Question

Usually answered in minutes!

Top Microsoft Compilers & Programming Tools Experts

Fred Block
Fred Block

Level 2 Expert

289 Answers

Robin Hill
Robin Hill

Level 3 Expert

1251 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Are you a Microsoft Compiler and Programming Tool Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...