?
Solved

whats wrong with my code????

Posted on 2000-03-27
9
Medium Priority
?
180 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
Industry Leaders: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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