Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if row exists

Status
Not open for further replies.

Griff389

Technical User
Jun 27, 2003
82
GB
I'd like to restrict users from opening a database more than once, by adding there network login name to a one column table (TblUsersLoggedIN) when they open the database.
Then if they try to open it again without closing it down, on another computer for example, it will first check to see if their username already exists in the table, and if it does, deny them access.

The problem is, I can establish the domain user name, but I can't think of the code to use to do the check to see if they (their username) already exist in the table.
e.g. if exist row in tblusersloggedin = ntdomainusername

Anyone any ideas?

 
I'd just query the table personally:

dim db as database
dim rs as recordset

set db = currentdb
set rs = db.openrecordset("SELECT * FROM tblusersloggedin WHERE myfield='" & ntdomainusername & "';")

if rs.recordcount = 1 then
msgbox "Already Logged In"
end if

set rs = nothing
set db = nothing
 
That works great. Cheers for the quick help.


Don't suppost you know the best way to add the username into the table when they open the db, and then delete the row when they click my button to close it do you ;)
I'm guessing a SQL statement will be easiest.
Select Into, and Delete from perhaps?
 
When they open the db have something like

set db = currentdb
set rs = db.openrecordset("tblusersloggedin")

with rs
.addnew
.fields(0) = ntuserdomain
.update
end with

and for closing you're right to suggest running a delete query.
 
Or you could use the delete method in a similar way to the above example.
 
Thanks RivetHead.

I used

DoCmd.SetWarnings (False)
DoCmd.RunSQL "DELETE * FROM TblUsersLoggedIn Where Username='" & NTDomainUserName & "';"
DoCmd.SetWarnings (True)

for the delete and works fine. Much appreciated. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top