Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

whats wrong with my code????

Posted on 2000-03-27
9
Medium Priority
?
181 Views
Last Modified: 2010-05-02
i wrote a small program to access the db and place it into msflexgrid. However i don't know waht is wrong in my sql statement, it give me the ff error"you tried to execute the query that does not included the specified expression 'username' as part of aggregate function" however if i replace the field name to *, it work.

can anyone here tell me also how to populate the data to the next row, because i only know how to populate the first row
here is my db
id(auto_no) username(text) userid(no.)ldate(date)ltime(date/time)event(text)

Private Sub Form_Load()

Dim line_text As String
Dim i

Dim cnESS
Set cnESS = New ADODB.Connection

With cnESS
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "c:\log\log.mdb"
    .Open , "", ""
  End With
 
  Dim rsESS As New ADODB.Recordset
    With rsESS
      .ActiveConnection = cnESS
      .CursorLocation = adUseClient
      .CursorType = adOpenKeyset
      .LockType = adLockOptimistic
    End With

  rsESS.Source = "select username, userid, ldate,event, max(ltime), min(ltime) from log_monitor" group by ldate, userid"
  rsESS.Open , , , , adCmdText
 'While Not rsESS.EOF
 With msf
   .ColWidth(0) = 1500
   .Col = 0
   .Text = rsESS(1)
   .ColWidth(1) = 300
   .Col = 1
   .Text = rsESS(2)
   .ColWidth(2) = 1000
   .Col = 2
   .Text = rsESS(3)
   .ColWidth(3) = 1000
   .Col = 3
   .Text = rsESS(4)
   .ColWidth(4) = 1000
   .Col = 4
   .Text = rsESS(5)
End With


  'MsgBox (rsESS("ltime"))
Close #1
   
   rsESS.Close

'MsgBox ("Finish Convert")

End Sub

0
Comment
Question by:binary1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2662561
Try this.
Grid is FlexGrid

Screen.MousePointer = vbHourglass
grid.Cols = rs2.Fields.Count
grid.Row = 0
j = -1
For Each fld In rs2.Fields
     j = j + 1
      grid.TextMatrix(0, j) = fld.Name
Next fld
rs2.MoveNext
grid.Rows = rs2.RecordCount + 1
i = 0
rs2.MoveFirst
'Move through each row in the recordset
Do Until rs2.EOF
i = i + 1
grid.Row = i
'Loop through all fields
j = -1
For Each fld In rs2.Fields
j = j + 1
grid.TextMatrix(i, j) = fld
Next fld
rs2.MoveNext
Loop
Screen.MousePointer = vbDefault
0
 
LVL 4

Expert Comment

by:mcix
ID: 2662578
If you are using a Group By (An aggregate function), then any fields you include in the Select must also appear in the Group By clause.


 
0
 

Author Comment

by:binary1
ID: 2662818
if my db have ff feild
id (auto_no),username, userid, event, ltime, ldate

i  need to get all the table fields  while limit the selection of the first login time(min(ltime)) and last of the logout time(max(ltime))for every days for each user (group by username,ldata)

can anyone show me the right way of the sql statement
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:jdhananjay
ID: 2662820
hi
 Try this

  rsESS.Source = "select username, userid, ldate,event, max(ltime), min(ltime) from log_monitor" group by ldate, userid,username,event,ltime

  rsESS.Open , , , , adCmdText

Good Luck
Jay
0
 

Author Comment

by:binary1
ID: 2662965
hi jdhananjay

u code work by including all the fields of the table, however it don't filter out some records that between the first login and last logout of the ltime.
0
 
LVL 1

Accepted Solution

by:
guyss earned 150 total points
ID: 2662972
if ldate and userid fully determine the
username and other field this wouldn't
be very efficient,

and easier and faster option is:
select first(username), userid, ldate,event, max(ltime), min(ltime) from log_monitor group by ldate, userid
0
 

Expert Comment

by:AshokKumar
ID: 2662989
opps. already two people answered. I guess i have to wait for the next question.

jdhananjay and mcix has given the answer for you friend. Go ahead.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2663095
I see you used my code.. <smile>

1. Try This..
 
SELECT DISTINCT(ldate, userid),
   username,
   event,
   max(ltime),
   min(ltime)
FROM log_monitor
ORDER by ldate, userid

2. In the following code..

 'While Not rsESS.EOF
 With msf
   .ColWidth(0) = 1500
   .Col = 0
   .Text = rsESS(1)
   .ColWidth(1) = 300
   .Col = 1
   .Text = rsESS(2)
   .ColWidth(2) = 1000
   .Col = 2
   .Text = rsESS(3)
   .ColWidth(3) = 1000
   .Col = 3
   .Text = rsESS(4)
   .ColWidth(4) = 1000
   .Col = 4
   .Text = rsESS(5)
End With

Reactivate the While loop and add a rsESS.MoveNext.
0
 
LVL 1

Expert Comment

by:j3877
ID: 2663171
try this:

rsESS.Source = "select 'username', 'userid', 'ldate','event', 'max(ltime)', 'min(ltime)' from 'log_monitor' group by 'ldate', 'userid' " 
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question