Welcome to dbFreaks.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

SQL and VB- how do u count records

 
   Database Help (Home) -> Visual Basic RSS
Related Topics:
Filtering records using textbox on form - Can I use the value of a bound textbox on an open form, as a criteria in a query. If so what would be the correct code for the SQL. If not how can I hold the required value (number) that is selected by the user from a combo box at startup, so that I can..

sql query returns in wrong format - Hi, Hope someone can help me with this. I have MS SQL 2000 database where i have Table and there a column wich is data type All data in this column is in form So why when i run .asp page with simple query to..

arrays - is there a way to the contents of an array (looping through the array) and storing each item in a comma delimited string? Thanks!

DataReport PageBreak - Hi everyone, I would like to know how to force pagebreak in a for example after 5 records printed. Thank you all

Possible Use of a Cursor - I have a complex query that I hope I can explain it well enough for everyone to I have a table that contains for work Contained in the table are these are groupings of machining
Next:  Visual Basic: SQL Format  
Author Message
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 1) Posted: Thu Feb 17, 2005 9:40 am
Post subject: SQL and VB- how do u count records
Archived from groups: comp>lang>basic>visual>database (more info?)

hi,

i've got a table in a access file, and i want to display a number on a
form, displaying a total unmber of a record.

e.g. i have a table with paper submissions, and i want to display the total
number of submissions. and i want to do it as a click event. how do i do
this? i need a count function??

this is what i've got

Private Sub Form_Load()
Dim i As Integer
Set Assignment2 = New ADODB.Connection
Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
Assignment2.Open
Set rs = New ADODB.Recordset

rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
adLockOptimistic

the above line, is for selecting everything. the text box is called
txtNumberOfSubmissions.

thanx

devin

 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
Jan Hyde

External


Since: Nov 06, 2003
Posts: 15



(Msg. 2) Posted: Thu Feb 17, 2005 9:40 am
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Devin Panchal" <d.panchal.TakeThisOut@ntlworld.com>'s wild thoughts
were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
following fruit:

 >hi,
 >
 > i've got a table in a access file, and i want to display a number on a
 >form, displaying a total unmber of a record.
 >
 >e.g. i have a table with paper submissions, and i want to display the total
 >number of submissions. and i want to do it as a click event. how do i do
 >this? i need a count function??
 >
 >this is what i've got
 >
 >Private Sub Form_Load()
 >Dim i As Integer
 >Set Assignment2 = New ADODB.Connection
 >Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
 >Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
 >Assignment2.Open
 >Set rs = New ADODB.Recordset
 >
 >rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
 >adLockOptimistic
 >
 >the above line, is for selecting everything. the text box is called
 >txtNumberOfSubmissions.

SELECT COUNT(*) etc

Will return 1 record containing the number of records
satisfying the criteria.

J


 >thanx
 >
 >devin
 >


Jan Hyde (VB MVP)

--
Belong: To take your time (Art. Moger)

[Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]" target="_blank">http://www.tvlicensing.biz/]</a><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
mickey

External


Since: Feb 15, 2005
Posts: 6



(Msg. 3) Posted: Thu Feb 17, 2005 10:40 am
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 4) Posted: Thu Feb 17, 2005 11:40 am
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

it says -1, and theres 21. ??
and SELECT COUNT, dont work either.

how should it look? this is what i got;

Private Sub cmdNumberOfSubmissions_Click()

End Sub

thanx
devin

"mickey" <mickeyATgruizelgruis.nl> wrote in message
news:fgc911la84v9qiklugoptigkeg19vi7ogi@4ax.com...
 > On Thu, 17 Feb 2005 13:46:51 +0000, Jan Hyde
 > <StellaDrinker.TakeThisOut@REMOVE.ME.uboot.com> you typed some letters in random
 > order:
 >
  > >"Devin Panchal" <d.panchal.TakeThisOut@ntlworld.com>'s wild thoughts
  > >were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
  > >following fruit:
  > >
   > >>hi,
   > >>
   > >> i've got a table in a access file, and i want to display a number on a
   > >>form, displaying a total unmber of a record.
   > >>
   > >>e.g. i have a table with paper submissions, and i want to display the
total
   > >>number of submissions. and i want to do it as a click event. how do i do
   > >>this? i need a count function??
   > >>
   > >>this is what i've got
   > >>
   > >>Private Sub Form_Load()
   > >>Dim i As Integer
   > >>Set Assignment2 = New ADODB.Connection
   > >>Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
   > >>Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
   > >>Assignment2.Open
   > >>Set rs = New ADODB.Recordset
   > >>
   > >>rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
   > >>adLockOptimistic
   > >>
   > >>the above line, is for selecting everything. the text box is called
   > >>txtNumberOfSubmissions.
  > >
  > >SELECT COUNT(*) etc
  > >
  > >Will return 1 record containing the number of records
  > >satisfying the criteria.
  > >
 >
 > You could also use:
 >
 > rs.movelast
 > rs.movefirst
 > txtNumberOfSubmissions.text = rs.recordcount
 >
 >
 >
 > Groetjenz,
 >
 > Mickey
 > --
 > #### gewoan skrieve su ast ut seist ####<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
Jan Hyde

External


Since: Nov 06, 2003
Posts: 15



(Msg. 5) Posted: Thu Feb 17, 2005 12:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Devin Panchal" <d.panchal RemoveThis @ntlworld.com>'s wild thoughts
were released on Thu, 17 Feb 2005 16:48:16 GMT bearing the
following fruit:

 >ok,
 >
 >i've got an access table called 'submission_info'. and i want to know how
 >many records there are in that table.
 >
 >i've got a button called 'cmdNumberOfSubmissions'.
 >and ive got a txt box called 'txtNumberOfSubmissions'. i want to display the
 >number of records in this boz, when the button has been clicked.
 >
 >do i need the following in the form;
 >
 >Private Sub Form_Load()
 >
 >Set Assignment2 = New ADODB.Connection
 >Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
 >Assignment2.ConnectionString = "C:\...Assignment2.mdb"
 >Assignment2.Open
 >Set rs = New ADODB.Recordset
 >
 >rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
 >adLockOptimistic
 >
 >End Sub
 >
 >thanx

**SELECT COUNT**

**DONT** tell me it doesn't work without telling me WHAT
doesn't work.... post code and give me details.

J

 >dev
 >
 >
 >"Jan Hyde" <StellaDrinker RemoveThis @REMOVE.ME.uboot.com> wrote in message
 >news:slh9115edk47ee1fnjg715akjlvc13lpjh@4ax.com...
  >> "Devin Panchal" <d.panchal RemoveThis @ntlworld.com>'s wild thoughts
  >> were released on Thu, 17 Feb 2005 16:00:30 GMT bearing the
  >> following fruit:
  >>
   >> >it says -1, and theres 21. ??
   >> >and SELECT COUNT, dont work either.
  >>
  >> Select COUNT does work Wink
  >>
  >> Give me more info.
  >>
  >> J
  >>
   >> >how should it look? this is what i got;
   >> >
   >> >Private Sub cmdNumberOfSubmissions_Click()
   >> >
   >> >End Sub
   >> >
   >> >thanx
   >> >devin
   >> >
   >> >"mickey" <mickeyATgruizelgruis.nl> wrote in message
   >> >news:fgc911la84v9qiklugoptigkeg19vi7ogi@4ax.com...
   >> >> On Thu, 17 Feb 2005 13:46:51 +0000, Jan Hyde
   >> >> <StellaDrinker RemoveThis @REMOVE.ME.uboot.com> you typed some letters in random
   >> >> order:
   >> >>
   >> >> >"Devin Panchal" <d.panchal RemoveThis @ntlworld.com>'s wild thoughts
   >> >> >were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
   >> >> >following fruit:
   >> >> >
   >> >> >>hi,
   >> >> >>
   >> >> >> i've got a table in a access file, and i want to display a number on
 >a
   >> >> >>form, displaying a total unmber of a record.
   >> >> >>
   >> >> >>e.g. i have a table with paper submissions, and i want to display the
   >> >total
   >> >> >>number of submissions. and i want to do it as a click event. how do i
 >do
   >> >> >>this? i need a count function??
   >> >> >>
   >> >> >>this is what i've got
   >> >> >>
   >> >> >>Private Sub Form_Load()
   >> >> >>Dim i As Integer
   >> >> >>Set Assignment2 = New ADODB.Connection
   >> >> >>Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
   >> >> >>Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
   >> >> >>Assignment2.Open
   >> >> >>Set rs = New ADODB.Recordset
   >> >> >>
   >> >> >>rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
   >> >> >>adLockOptimistic
   >> >> >>
   >> >> >>the above line, is for selecting everything. the text box is called
   >> >> >>txtNumberOfSubmissions.
   >> >> >
   >> >> >SELECT COUNT(*) etc
   >> >> >
   >> >> >Will return 1 record containing the number of records
   >> >> >satisfying the criteria.
   >> >> >
   >> >>
   >> >> You could also use:
   >> >>
   >> >> rs.movelast
   >> >> rs.movefirst
   >> >> txtNumberOfSubmissions.text = rs.recordcount
   >> >>
   >> >>
   >> >>
   >> >> Groetjenz,
   >> >>
   >> >> Mickey
   >> >> --
   >> >> #### gewoan skrieve su ast ut seist ####
   >> >
  >>
  >>
  >> Jan Hyde (VB MVP)
  >>
  >> --
  >> Metallurgist: Someone who is allergic to iron. (Leo Roston)
  >>
<font color=green>  >> [Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]</font" target="_blank">http://www.tvlicensing.biz/]</font</a>>
  >>
 >


Jan Hyde (VB MVP)

--
"Streakers re-pant! Your end is in sight." (McMail)

[Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]" target="_blank">http://www.tvlicensing.biz/]</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 6) Posted: Thu Feb 17, 2005 12:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

ok,

i've got an access table called 'submission_info'. and i want to know how
many records there are in that table.

i've got a button called 'cmdNumberOfSubmissions'.
and ive got a txt box called 'txtNumberOfSubmissions'. i want to display the
number of records in this boz, when the button has been clicked.

do i need the following in the form;

Private Sub Form_Load()

Set Assignment2 = New ADODB.Connection
Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
Assignment2.ConnectionString = "C:\...Assignment2.mdb"
Assignment2.Open
Set rs = New ADODB.Recordset

rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
adLockOptimistic

End Sub

thanx

dev


"Jan Hyde" <StellaDrinker.RemoveThis@REMOVE.ME.uboot.com> wrote in message
news:slh9115edk47ee1fnjg715akjlvc13lpjh@4ax.com...
 > "Devin Panchal" <d.panchal.RemoveThis@ntlworld.com>'s wild thoughts
 > were released on Thu, 17 Feb 2005 16:00:30 GMT bearing the
 > following fruit:
 >
  > >it says -1, and theres 21. ??
  > >and SELECT COUNT, dont work either.
 >
 > Select COUNT does work Wink
 >
 > Give me more info.
 >
 > J
 >
  > >how should it look? this is what i got;
  > >
  > >Private Sub cmdNumberOfSubmissions_Click()
  > >
  > >End Sub
  > >
  > >thanx
  > >devin
  > >
  > >"mickey" <mickeyATgruizelgruis.nl> wrote in message
  > >news:fgc911la84v9qiklugoptigkeg19vi7ogi@4ax.com...
   > >> On Thu, 17 Feb 2005 13:46:51 +0000, Jan Hyde
   > >> <StellaDrinker.RemoveThis@REMOVE.ME.uboot.com> you typed some letters in random
   > >> order:
   > >>
   > >> >"Devin Panchal" <d.panchal.RemoveThis@ntlworld.com>'s wild thoughts
   > >> >were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
   > >> >following fruit:
   > >> >
   > >> >>hi,
   > >> >>
   > >> >> i've got a table in a access file, and i want to display a number on
a
   > >> >>form, displaying a total unmber of a record.
   > >> >>
   > >> >>e.g. i have a table with paper submissions, and i want to display the
  > >total
   > >> >>number of submissions. and i want to do it as a click event. how do i
do
   > >> >>this? i need a count function??
   > >> >>
   > >> >>this is what i've got
   > >> >>
   > >> >>Private Sub Form_Load()
   > >> >>Dim i As Integer
   > >> >>Set Assignment2 = New ADODB.Connection
   > >> >>Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
   > >> >>Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
   > >> >>Assignment2.Open
   > >> >>Set rs = New ADODB.Recordset
   > >> >>
   > >> >>rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
   > >> >>adLockOptimistic
   > >> >>
   > >> >>the above line, is for selecting everything. the text box is called
   > >> >>txtNumberOfSubmissions.
   > >> >
   > >> >SELECT COUNT(*) etc
   > >> >
   > >> >Will return 1 record containing the number of records
   > >> >satisfying the criteria.
   > >> >
   > >>
   > >> You could also use:
   > >>
   > >> rs.movelast
   > >> rs.movefirst
   > >> txtNumberOfSubmissions.text = rs.recordcount
   > >>
   > >>
   > >>
   > >> Groetjenz,
   > >>
   > >> Mickey
   > >> --
   > >> #### gewoan skrieve su ast ut seist ####
  > >
 >
 >
 > Jan Hyde (VB MVP)
 >
 > --
 > Metallurgist: Someone who is allergic to iron. (Leo Roston)
 >
<font color=purple> > [Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]</font" target="_blank">http://www.tvlicensing.biz/]</font</a>>
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
mickey

External


Since: Feb 15, 2005
Posts: 6



(Msg. 7) Posted: Thu Feb 17, 2005 12:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Back to top
Login to vote
Jan Hyde

External


Since: Nov 06, 2003
Posts: 15



(Msg. 8) Posted: Thu Feb 17, 2005 12:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Devin Panchal" <d.panchal.DeleteThis@ntlworld.com>'s wild thoughts
were released on Thu, 17 Feb 2005 16:00:30 GMT bearing the
following fruit:

 >it says -1, and theres 21. ??
 >and SELECT COUNT, dont work either.

Select COUNT does work Wink

Give me more info.

J

 >how should it look? this is what i got;
 >
 >Private Sub cmdNumberOfSubmissions_Click()
 >
 >End Sub
 >
 >thanx
 >devin
 >
 >"mickey" <mickeyATgruizelgruis.nl> wrote in message
 >news:fgc911la84v9qiklugoptigkeg19vi7ogi@4ax.com...
  >> On Thu, 17 Feb 2005 13:46:51 +0000, Jan Hyde
  >> <StellaDrinker.DeleteThis@REMOVE.ME.uboot.com> you typed some letters in random
  >> order:
  >>
   >> >"Devin Panchal" <d.panchal.DeleteThis@ntlworld.com>'s wild thoughts
   >> >were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
   >> >following fruit:
   >> >
   >> >>hi,
   >> >>
   >> >> i've got a table in a access file, and i want to display a number on a
   >> >>form, displaying a total unmber of a record.
   >> >>
   >> >>e.g. i have a table with paper submissions, and i want to display the
 >total
   >> >>number of submissions. and i want to do it as a click event. how do i do
   >> >>this? i need a count function??
   >> >>
   >> >>this is what i've got
   >> >>
   >> >>Private Sub Form_Load()
   >> >>Dim i As Integer
   >> >>Set Assignment2 = New ADODB.Connection
   >> >>Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
   >> >>Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
   >> >>Assignment2.Open
   >> >>Set rs = New ADODB.Recordset
   >> >>
   >> >>rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
   >> >>adLockOptimistic
   >> >>
   >> >>the above line, is for selecting everything. the text box is called
   >> >>txtNumberOfSubmissions.
   >> >
   >> >SELECT COUNT(*) etc
   >> >
   >> >Will return 1 record containing the number of records
   >> >satisfying the criteria.
   >> >
  >>
  >> You could also use:
  >>
  >> rs.movelast
  >> rs.movefirst
  >> txtNumberOfSubmissions.text = rs.recordcount
  >>
  >>
  >>
  >> Groetjenz,
  >>
  >> Mickey
  >> --
  >> #### gewoan skrieve su ast ut seist ####
 >


Jan Hyde (VB MVP)

--
Metallurgist: Someone who is allergic to iron. (Leo Roston)

[Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]" target="_blank">http://www.tvlicensing.biz/]</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 9) Posted: Thu Feb 17, 2005 1:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

i dont know how to use the 'select count' code.

and the code the other guy gave;
Private Sub cmdNumberOfSubmissions_Click()

rs.MoveLast
rs.MoveFirst

txtNumberOfSubmissions.Text = rs.RecordCount


End Sub

gives me '-1'. how should i use the select count. how would the code look?
thats all the code i got, cos i dont understand how to use select count.

thanx

dev

"Jan Hyde" <StellaDrinker.TakeThisOut@REMOVE.ME.uboot.com> wrote in message
news:j1j9119l15eveq6ash56q5goaq8skk6nq1@4ax.com...
 > "Devin Panchal" <d.panchal.TakeThisOut@ntlworld.com>'s wild thoughts
 > were released on Thu, 17 Feb 2005 16:48:16 GMT bearing the
 > following fruit:
 >
  > >ok,
  > >
  > >i've got an access table called 'submission_info'. and i want to know how
  > >many records there are in that table.
  > >
  > >i've got a button called 'cmdNumberOfSubmissions'.
  > >and ive got a txt box called 'txtNumberOfSubmissions'. i want to display
the
  > >number of records in this boz, when the button has been clicked.
  > >
  > >do i need the following in the form;
  > >
  > >Private Sub Form_Load()
  > >
  > >Set Assignment2 = New ADODB.Connection
  > >Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
  > >Assignment2.ConnectionString = "C:\...Assignment2.mdb"
  > >Assignment2.Open
  > >Set rs = New ADODB.Recordset
  > >
  > >rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
  > >adLockOptimistic
  > >
  > >End Sub
  > >
  > >thanx
 >
 > **SELECT COUNT**
 >
 > **DONT** tell me it doesn't work without telling me WHAT
 > doesn't work.... post code and give me details.
 >
 > J
 >
  > >dev
  > >
  > >
  > >"Jan Hyde" <StellaDrinker.TakeThisOut@REMOVE.ME.uboot.com> wrote in message
  > >news:slh9115edk47ee1fnjg715akjlvc13lpjh@4ax.com...
   > >> "Devin Panchal" <d.panchal.TakeThisOut@ntlworld.com>'s wild thoughts
   > >> were released on Thu, 17 Feb 2005 16:00:30 GMT bearing the
   > >> following fruit:
   > >>
   > >> >it says -1, and theres 21. ??
   > >> >and SELECT COUNT, dont work either.
   > >>
   > >> Select COUNT does work Wink
   > >>
   > >> Give me more info.
   > >>
   > >> J
   > >>
   > >> >how should it look? this is what i got;
   > >> >
   > >> >Private Sub cmdNumberOfSubmissions_Click()
   > >> >
   > >> >End Sub
   > >> >
   > >> >thanx
   > >> >devin
   > >> >
   > >> >"mickey" <mickeyATgruizelgruis.nl> wrote in message
   > >> >news:fgc911la84v9qiklugoptigkeg19vi7ogi@4ax.com...
   > >> >> On Thu, 17 Feb 2005 13:46:51 +0000, Jan Hyde
   > >> >> <StellaDrinker.TakeThisOut@REMOVE.ME.uboot.com> you typed some letters in random
   > >> >> order:
   > >> >>
   > >> >> >"Devin Panchal" <d.panchal.TakeThisOut@ntlworld.com>'s wild thoughts
   > >> >> >were released on Thu, 17 Feb 2005 13:36:50 GMT bearing the
   > >> >> >following fruit:
   > >> >> >
   > >> >> >>hi,
   > >> >> >>
   > >> >> >> i've got a table in a access file, and i want to display a number
on
  > >a
   > >> >> >>form, displaying a total unmber of a record.
   > >> >> >>
   > >> >> >>e.g. i have a table with paper submissions, and i want to display
the
   > >> >total
   > >> >> >>number of submissions. and i want to do it as a click event. how
do i
  > >do
   > >> >> >>this? i need a count function??
   > >> >> >>
   > >> >> >>this is what i've got
   > >> >> >>
   > >> >> >>Private Sub Form_Load()
   > >> >> >>Dim i As Integer
   > >> >> >>Set Assignment2 = New ADODB.Connection
   > >> >> >>Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
   > >> >> >>Assignment2.ConnectionString = "C:\D...\Assignment2.mdb"
   > >> >> >>Assignment2.Open
   > >> >> >>Set rs = New ADODB.Recordset
   > >> >> >>
   > >> >> >>rs.Open "select * from submission_info", Assignment2,
adOpenDynmic,
   > >> >> >>adLockOptimistic
   > >> >> >>
   > >> >> >>the above line, is for selecting everything. the text box is
called
   > >> >> >>txtNumberOfSubmissions.
   > >> >> >
   > >> >> >SELECT COUNT(*) etc
   > >> >> >
   > >> >> >Will return 1 record containing the number of records
   > >> >> >satisfying the criteria.
   > >> >> >
   > >> >>
   > >> >> You could also use:
   > >> >>
   > >> >> rs.movelast
   > >> >> rs.movefirst
   > >> >> txtNumberOfSubmissions.text = rs.recordcount
   > >> >>
   > >> >>
   > >> >>
   > >> >> Groetjenz,
   > >> >>
   > >> >> Mickey
   > >> >> --
   > >> >> #### gewoan skrieve su ast ut seist ####
   > >> >
   > >>
   > >>
   > >> Jan Hyde (VB MVP)
   > >>
   > >> --
   > >> Metallurgist: Someone who is allergic to iron. (Leo Roston)
   > >>
<font color=brown>   > >> [Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]</font" target="_blank">http://www.tvlicensing.biz/]</font</a>>
   > >>
  > >
 >
 >
 > Jan Hyde (VB MVP)
 >
 > --
 > "Streakers re-pant! Your end is in sight." (McMail)
 >
<font color=purple> > [Abolish the TV Licence - <a style='text-decoration: underline;' href="http://www.tvlicensing.biz/]</font" target="_blank">http://www.tvlicensing.biz/]</font</a>>
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
Michael B. Johnson

External


Since: May 14, 2004
Posts: 16



(Msg. 10) Posted: Thu Feb 17, 2005 3:11 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 17 Feb 2005 17:37:40 GMT, "Devin Panchal"
<d.panchal.DeleteThis@ntlworld.com> wrote:

 >i dont know how to use the 'select count' code.
 >
 >and the code the other guy gave;
 >Private Sub cmdNumberOfSubmissions_Click()
 >
 >rs.MoveLast
 >rs.MoveFirst
 >
 >txtNumberOfSubmissions.Text = rs.RecordCount
 >
 >
 >End Sub
 >
 >gives me '-1'. how should i use the select count. how would the code look?
 >thats all the code i got, cos i dont understand how to use select count.

The "other guy" gave you good code that works with DAO. You must be
using ADO, which behaves differently, depending upon the provider you
are using. Did you tell him what data access technology you were
using, in your request for help?

As for SELECT COUNT, it goes something like this:

<air code>
rs.Open "SELECT Count(*) FROM Table_Name"

Debug.Print "There are " & rs.Fields( 0 ).Value & " matching records."
</air code>
_______________________
Michael B. Johnson<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 11) Posted: Fri Feb 18, 2005 6:40 am
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

sorry, i'm using ADO.
i've tried the code u gave me, and that has an error. it says 'the operation
is not allowed when the object is open'.

this is what 've got;

Private Sub cmdNumberOfSubmissions_Click()

rs.Open "SELECT Count(*) FROM submission_info"

Debug.Print "There are " & rs.Fields(0).Value & " matching records."

End Sub

i want to display the number in a txt box 'txtNumberOfSubmissions'.
also do i need any of the follwing code in the form;

Private Sub Form_Load()

Set Assignment2 = New ADODB.Connection
Assignment2.Provider = "Microsoft.Jet.OLEDB.4.0;"
Assignment2.ConnectionString = "C:\...\Assignment2.mdb"
Assignment2.Open
Set rs = New ADODB.Recordset

rs.Open "select * from submission_info", Assignment2, adOpenDynmic,
adLockOptimistic

End Sub

thanx

devin

"Michael B. Johnson" <mjohnson.DeleteThis@veribox.net> wrote in message
news:fdu9115lfk4ok39qvmot1lt0b2vg6om6a6@4ax.com...
 > On Thu, 17 Feb 2005 17:37:40 GMT, "Devin Panchal"
 > <d.panchal.DeleteThis@ntlworld.com> wrote:
 >
  > >i dont know how to use the 'select count' code.
  > >
  > >and the code the other guy gave;
  > >Private Sub cmdNumberOfSubmissions_Click()
  > >
  > >rs.MoveLast
  > >rs.MoveFirst
  > >
  > >txtNumberOfSubmissions.Text = rs.RecordCount
  > >
  > >
  > >End Sub
  > >
  > >gives me '-1'. how should i use the select count. how would the code
look?
  > >thats all the code i got, cos i dont understand how to use select count.
 >
 > The "other guy" gave you good code that works with DAO. You must be
 > using ADO, which behaves differently, depending upon the provider you
 > are using. Did you tell him what data access technology you were
 > using, in your request for help?
 >
 > As for SELECT COUNT, it goes something like this:
 >
 > <air code>
 > rs.Open "SELECT Count(*) FROM Table_Name"
 >
 > Debug.Print "There are " & rs.Fields( 0 ).Value & " matching records."
 > </air code>
 > _______________________
 > Michael B. Johnson<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
Randy Day

External


Since: Oct 06, 2003
Posts: 50



(Msg. 12) Posted: Fri Feb 18, 2005 10:16 am
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Devin Panchal wrote:

 > sorry, i'm using ADO.
 > i've tried the code u gave me, and that has an error. it says 'the operation
 > is not allowed when the object is open'.
 >
 > this is what 've got;
 >
 > Private Sub cmdNumberOfSubmissions_Click()
 >
 > rs.Open "SELECT Count(*) FROM submission_info"
 >
 > Debug.Print "There are " & rs.Fields(0).Value & " matching records."
 >
 > End Sub
 >
 > i want to display the number in a txt box 'txtNumberOfSubmissions'.
 > also do i need any of the follwing code in the form;

Devin, doesn't the 'rs.recordcount' property give you
the number you want?

In any case, you need to close the recordset before
trying to 'open' it again. Keep in mind that your
previous search result is now GONE when you do this.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 13) Posted: Sat Feb 19, 2005 7:40 pm
Post subject: Re: SQL and VB- how do u count records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

thanx. i sorted it. lol, only got 2 lines of code.

Wink

devin


"Randy Day" <ruthal DeleteThis @sasktel.nex> wrote in message
news:111c1m73soiunac@corp.supernews.com...
 > Devin Panchal wrote:
 >
  > > sorry, i'm using ADO.
  > > i've tried the code u gave me, and that has an error. it says 'the
operation
  > > is not allowed when the object is open'.
  > >
  > > this is what 've got;
  > >
  > > Private Sub cmdNumberOfSubmissions_Click()
  > >
  > > rs.Open "SELECT Count(*) FROM submission_info"
  > >
  > > Debug.Print "There are " & rs.Fields(0).Value & " matching records."
  > >
  > > End Sub
  > >
  > > i want to display the number in a txt box 'txtNumberOfSubmissions'.
  > > also do i need any of the follwing code in the form;
 >
 > Devin, doesn't the 'rs.recordcount' property give you
 > the number you want?
 >
 > In any case, you need to close the recordset before
 > trying to 'open' it again. Keep in mind that your
 > previous search result is now GONE when you do this.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL and VB- how do u count records 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]