username table

S

Stu Dongel

hello all

i have a bit of a problem im trying to work around here. i have a database,
thet is needs to be accesable by a metric ton of ppl. but not accesable by
a ton more. what i wanted to do was set up a table lets call it "tblusers".
the table contains 1 field, containg a username.

i was thinking of just setting up a form with a text box with a field that
says username and a button. in the button script i would have some sort of
if then statment that querys to see if the username they put in the box
exists in the tbluser. if yes proced to main form, if no fail out to a
message box.

im not much of a vb coder, this is probebly really easy, but im affraid i
dont have the sytax.

could anyone give me a lil nudge in the right direction?

thanks
stu
 
T

tina

well, there are a couple ways to do it that i can think of. here's one way
you could try:

in the command button's On Click event procedure,

If DCount("username","tblusers","username = " &
Forms!FormName!ControlName)<1 Then
Msgbox "You're not authorized to use this database."
Else
DoCmd.OpenForm "FormName"
End If

substitute your actual table, field, form and control names, of course.
hth
 
T

tina

oops! the DCount() syntax in the previous post should work if the username
field is number data type, but for text data type you'll have to change it a
little:

DCount("username","tblusers","username = '" & Forms!FormName!ControlName &
"'")<1
 
K

KaiRich

Hi
I've just tested the code below in Access 2000 and it works
It is if you want to have a Username and a Password, you need a table with both of these fields
Best regards - Ka

Sub cmdOkay_Click(
' CommandButton cmdOka
' TextBox txtUserNam
' TextBox txtPassword - Properties, Data, Input Mask, Passwor
' Table tblUsers - fields; Username, Passwor

Dim FoundUserName As Boolea
Dim PasswordMatches As Boolea
Const MacroName As String = "Check Username and Password
Dim rstFundBodies As DAO.Recordset ' In Access 2003 ADO.Recordset probably bette
Set rstFundBodies = CurrentDb.OpenRecordset("tbl_FundBodies"
rstFundBodies.MoveFirst ' Starts at first record in tabl
D

If rstFundBodies!FundBodyTitle = txtUserNAme.Value The
FoundUserName = Tru
If rstFundBodies!FundBodyCode = txtPassword.Value Then PasswordMatches = Tru
Exit D
End I
rstFundBodies.MoveNext ' Moves to next record in tabl
If rstFundBodies.EOF Then Exit Do ' Stop looking when reach last recor
Loo
rstFundBodies.Close ' Closes table, not really require
If FoundUserName = False The
' Person not in tblUser
MsgBox "You are not a listed user." & vbCr &
"Please speak with database administrator.",
vbCritical & vbOKOnly, MacroNam
Application.CloseCurrentDatabas
Els
' Person is in tblUser
If PasswordMatches = False The
' But password wron
MsgBox "You are have entered an incorrect password." & vbCr &
"Please speak with database administrator.",
vbCritical & vbOKOnly, MacroNam
Application.CloseCurrentDatabas
Els
' Password is correc
' No actio
End I
End I
End Su


----- Stu Dongel wrote: ----

hello al

i have a bit of a problem im trying to work around here. i have a database
thet is needs to be accesable by a metric ton of ppl. but not accesable b
a ton more. what i wanted to do was set up a table lets call it "tblusers"
the table contains 1 field, containg a username

i was thinking of just setting up a form with a text box with a field tha
says username and a button. in the button script i would have some sort o
if then statment that querys to see if the username they put in the bo
exists in the tbluser. if yes proced to main form, if no fail out to
message box

im not much of a vb coder, this is probebly really easy, but im affraid
dont have the sytax

could anyone give me a lil nudge in the right direction

thank
st
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top