Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
The following login script adds a record that records the computername, username, and datetime of login then saves the autonumber field for reference at logout. I am moving this to a SQL server db. It works except I have been unable to retrieve the identity field. Note the SQL statement, the DISTINCT property returns the entire column. Any suggestions how I can return to this record to enter the logout datetime?
============================================
strConnString = "Provider=SQLOLEDB;Data Source=\\server\db;uid=temp;pwd=temp"
SQL = "SELECT DISTINCT ID FROM Logins"objConn.Open "File name=" & ".\test.udl"
Set objRS = CreateObject("ADODB.Recordset")
objRS.Open "Logins", objConn, 2, 2objRS.AddNew
objRS("ComputerName") = ComputerName
objRS("UserID") = UserID
objRS("TimeIn") = Now
AutoNum = objRS("ID")
objRS.Update
msgbox autonumobjRS.Close
========================================

Sorry, but you are wrong. the DISTICT command retrieves only ONE instance of whatever you are selecting.
SELECT DISTINCT ID FROM Logins
Returns the following:
ID
ID
ID
IDYou want to select more that just the ID, you want ComputerName, UserId, TimeIN, AND ID. To do that you need to specify that you want more than just the ID.
SELECT * FROM Logins
or
SELECT DISTINCT ID, ComputerName, UserID, TimeIN FROM LoginsHope this helps,
Chi Happens

Running "Select DISTINCT from logins" in Query Analyzer returns the entire column, just as you indicated:
ID
ID
ID
...
I need to retrieve only the ID of the row just inserted, not the entire column. I need to come back to this record later and this is my unique key to finding it. The other fields are duplicated.

I ended up doing a search for the last record with the userid:
===========================================
strConnString = "Provider=SQLOLEDB;Data Source=\\ac2manage\logins;uid=temp;pwd=temp"objConn.Open "File name=" & ".\test.udl"
Set objRS = CreateObject("ADODB.Recordset")
objRS.Open "Logins", objConn, 2, 2objRS.AddNew
objRS("ComputerName") = ComputerName
objRS("UserID") = UserID
objRS("TimeIn") = NowobjRS.Update
objRS.Close
SQL = "SELECT ID FROM Logins WHERE UserID = '" & userid & "'"
objRS.Open SQL,objConn, 2, 2Dim last
last = 0
while not objrs.eof
if objrs("ID") > last then last = objrs("ID")
objrs.movenext
wendautonum = last
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
=======================================

![]() |
finding last lines of tex...
|
Currency problems in VB6
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |