By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

getting user name and insert query

P: 43
Hi..

how can i get the username who login in the form? I need to display it like the one above this form..

and can anybody give me an example of function how to use the insert into in database..this is my code how I insert the values..

Expand|Select|Wrap|Line Numbers
  1.                   If rsmain.Supports(adAddNew) Then
  2.                     With rsmain
  3.                         .AddNew
  4.                         .Fields("case_id") = case_id
  5.                         .Fields("category") = cmbcat
  6.                         .Fields("case_summary") = case_sum
  7.                         .Fields("sub_case") = sub_case2
  8.                         .Fields("priority") = cmbpriority
  9.                         .Fields("start_date_time") = txtstart
  10.                         .Fields("escalated_date_time") = txtescalated
  11.                         .Fields("clear_date_time") = txtclear
  12.                         .Fields("status") = txtstat
  13.                         .Fields("tempstat") = frstatus
  14.                         .Fields("escalated_to") = cmbescalatedto
  15.                         .Fields("class") = cmbclass
  16.                         .Fields("total_complaints") = txttotal
  17.                         .Fields("case_source") = cmbsource
  18.                         .Fields("prob_desc") = txtproblem
  19.                         .Fields("worklog") = txtlog
  20.                         .Fields("case_attach") = txtattach
  21.                         .Fields("res_details") = details
  22.                         .Fields("res_sum") = ressum
  23.                         .Update
thanx in advance..


-cassey
Jan 15 '07 #1
Share this Question
Share on Google+
8 Replies


100+
P: 1,646
Hi..

how can i get the username who login in the form? I need to display it like the one above this form..

and can anybody give me an example of function how to use the insert into in database..this is my code how I insert the values..

If rsmain.Supports(adAddNew) Then
With rsmain
.AddNew
.Fields("case_id") = case_id
.Fields("category") = cmbcat
.Fields("case_summary") = case_sum
.Fields("sub_case") = sub_case2
.Fields("priority") = cmbpriority
.Fields("start_date_time") = txtstart
.Fields("escalated_date_time") = txtescalated
.Fields("clear_date_time") = txtclear
.Fields("status") = txtstat
.Fields("tempstat") = frstatus
.Fields("escalated_to") = cmbescalatedto
.Fields("class") = cmbclass
.Fields("total_complaints") = txttotal
.Fields("case_source") = cmbsource
.Fields("prob_desc") = txtproblem
.Fields("worklog") = txtlog
.Fields("case_attach") = txtattach
.Fields("res_details") = details
.Fields("res_sum") = ressum
.Update

thanx in advance..


-cassey
Hi cassey, would you please post the code for the login form? The code above makes no reference to the username
Jan 15 '07 #2

P: 43
Hi cassey, would you please post the code for the login form? The code above makes no reference to the username
sure..but the code above refers to the insert query..i also need help in inserting a query in database..hope you give example too..
tanx..

heres the code for login:



Expand|Select|Wrap|Line Numbers
  1.   Set RS = New adodb.Recordset
  2.    Set RS.ActiveConnection = CurrentProject.Connection
  3.  
  4.         RS.Open "Select Count(*) as cnt from PASSWORD where initial = '" &    Me![txtusername] & "' AND password = '" & Me![txtpassword] & "'"
  5.     If RS("cnt") = 0 Then
  6.        MsgBox "INVALID Username/Password. Please Try again!"
  7.  
  8.        txtpassword = ""
  9.     Else
  10.       RS.Close
  11.             MsgBox ("You are now login")
  12.             'Forms!menu.Visible = True
  13.             DoCmd.OpenForm "mainmenu"
  14.             Forms!frmlogin.Visible = False
  15.  
  16.             Exit Sub
  17.          End If
Jan 15 '07 #3

markmcgookin
Expert 100+
P: 648
Hey, here is some code I recently used for a login button, the username attribute is actually never defined, it is simply searched for and if it is there then the password validation kicks in.

but you could define it by

Dim userName as String
...
userName = me.txtMemberName

(or from another form

username = Nz(Forms!frmLogin!txtMembername, ""

)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnLogin_Click()
  3.  
  4. Dim un As String
  5. Dim userType As String
  6. Dim status As String
  7.  
  8. If IsNull(DLookup("userPassword", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34))) Then
  9.  
  10.    ' not found
  11.  
  12.    MsgBox "Sorry, your username was not found, Please re-enter a valid username"
  13.    Exit Sub
  14.  
  15. Else
  16.  
  17.    If DLookup("userPassword", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34)) <> Me.txtPassword Then
  18.  
  19.       ' wrong password
  20.       MsgBox "Sorry, your password does not match the username " & 
  21.  
  22. DLookup("userPassword", "tblUser", "UserID=" _
  23.       & Chr(34) & Me.txtMembername & Chr(34)) & ", Please re-enter your password"
  24.       Exit Sub
  25.  
  26. Else
  27.  
  28. If status = "Inactive" Then
  29.    MsgBox "You are not currently signed into the AR System, please sign in before using JR"
  30.  
  31.    Exit Sub
  32.  
  33.    Else
  34.       ' OK
  35.  
  36.       userType = DLookup("userType", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34))
  37.  
  38.          End If
  39.       End If
  40.  
  41.       If userType = "Engineer" Then
  42.       DoCmd.OpenForm "frmEngMenu"
  43.  
  44.       Else
  45.       DoCmd.OpenForm "frmForMenu"
  46.  
  47.       End If
  48.  
  49.    End If
  50.  
  51.  
PS - If you are having trouble with Update/Insert SQL etc check out my post
http://www.thescripts.com/forum/thread586633.html

If you cant find the answer to your question there, there is a post on the bottom of the 2nd page linking to Access FAQs where your answr should be.
Jan 15 '07 #4

100+
P: 1,646
sure..but the code above refers to the insert query..i also need help in inserting a query in database..hope you give example too..
tanx..

heres the code for login:



Expand|Select|Wrap|Line Numbers
  1.   Set RS = New adodb.Recordset
  2.    Set RS.ActiveConnection = CurrentProject.Connection
  3.  
  4.         RS.Open "Select Count(*) as cnt from PASSWORD where initial = '" &    Me![txtusername] & "' AND password = '" & Me![txtpassword] & "'"
  5.     If RS("cnt") = 0 Then
  6.        MsgBox "INVALID Username/Password. Please Try again!"
  7.  
  8.        txtpassword = ""
  9.     Else
  10.       RS.Close
  11.             MsgBox ("You are now login")
  12.             'Forms!menu.Visible = True
  13.             DoCmd.OpenForm "mainmenu"
  14.             Forms!frmlogin.Visible = False
  15.  
  16.             Exit Sub
  17.          End If
So you have the username stored here:
Forms!frmlogin![txtusername]
and you should be able to access it at anytime because it has not been closed. It is just not visible.
Jan 15 '07 #5

ADezii
Expert 5K+
P: 8,638
Hi..

how can i get the username who login in the form? I need to display it like the one above this form..

and can anybody give me an example of function how to use the insert into in database..this is my code how I insert the values..

Expand|Select|Wrap|Line Numbers
  1.                   If rsmain.Supports(adAddNew) Then
  2.                     With rsmain
  3.                         .AddNew
  4.                         .Fields("case_id") = case_id
  5.                         .Fields("category") = cmbcat
  6.                         .Fields("case_summary") = case_sum
  7.                         .Fields("sub_case") = sub_case2
  8.                         .Fields("priority") = cmbpriority
  9.                         .Fields("start_date_time") = txtstart
  10.                         .Fields("escalated_date_time") = txtescalated
  11.                         .Fields("clear_date_time") = txtclear
  12.                         .Fields("status") = txtstat
  13.                         .Fields("tempstat") = frstatus
  14.                         .Fields("escalated_to") = cmbescalatedto
  15.                         .Fields("class") = cmbclass
  16.                         .Fields("total_complaints") = txttotal
  17.                         .Fields("case_source") = cmbsource
  18.                         .Fields("prob_desc") = txtproblem
  19.                         .Fields("worklog") = txtlog
  20.                         .Fields("case_attach") = txtattach
  21.                         .Fields("res_details") = details
  22.                         .Fields("res_sum") = ressum
  23.                         .Update
thanx in advance..


-cassey
In you are referring to the standard Access Dialog Log-In when Security is set on a Database, the Name of the Current User can be found by the CurrentUser() Method:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "The Current User of this Database is " & CurrentUser()
Jan 15 '07 #6

markmcgookin
Expert 100+
P: 648
So you have the username stored here:
Forms!frmlogin![txtusername]
and you should be able to access it at anytime because it has not been closed. It is just not visible.

Indeed! That is a reference to the other open form, keeping forms maximised in the background will keep this variable usable. For a logout button all I have is a macro on the button that closes the menu, then the login form and then re-opens the login form, wiping the values, and thus logign the user out.
Jan 15 '07 #7

P: 43
Hey, here is some code I recently used for a login button, the username attribute is actually never defined, it is simply searched for and if it is there then the password validation kicks in.

but you could define it by

Dim userName as String
...
userName = me.txtMemberName

(or from another form

username = Nz(Forms!frmLogin!txtMembername, ""

)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnLogin_Click()
  3.  
  4. Dim un As String
  5. Dim userType As String
  6. Dim status As String
  7.  
  8. If IsNull(DLookup("userPassword", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34))) Then
  9.  
  10.    ' not found
  11.  
  12.    MsgBox "Sorry, your username was not found, Please re-enter a valid username"
  13.    Exit Sub
  14.  
  15. Else
  16.  
  17.    If DLookup("userPassword", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34)) <> Me.txtPassword Then
  18.  
  19.       ' wrong password
  20.       MsgBox "Sorry, your password does not match the username " & 
  21.  
  22. DLookup("userPassword", "tblUser", "UserID=" _
  23.       & Chr(34) & Me.txtMembername & Chr(34)) & ", Please re-enter your password"
  24.       Exit Sub
  25.  
  26. Else
  27.  
  28. If status = "Inactive" Then
  29.    MsgBox "You are not currently signed into the AR System, please sign in before using JR"
  30.  
  31.    Exit Sub
  32.  
  33.    Else
  34.       ' OK
  35.  
  36.       userType = DLookup("userType", "tblUser", "UserID=" & Chr(34) & Me.txtMembername & Chr(34))
  37.  
  38.          End If
  39.       End If
  40.  
  41.       If userType = "Engineer" Then
  42.       DoCmd.OpenForm "frmEngMenu"
  43.  
  44.       Else
  45.       DoCmd.OpenForm "frmForMenu"
  46.  
  47.       End If
  48.  
  49.    End If
  50.  
  51.  
PS - If you are having trouble with Update/Insert SQL etc check out my post
http://www.thescripts.com/forum/thread586633.html

If you cant find the answer to your question there, there is a post on the bottom of the 2nd page linking to Access FAQs where your answr should be.

thanx for all the reply..but I need to display the user in the main form..how can i do that??
Jan 16 '07 #8

markmcgookin
Expert 100+
P: 648
thanx for all the reply..but I need to display the user in the main form..how can i do that??
Either using some kind of AFTER UPDATE function on the textbox you could set another text box to come visible, read only and populate it with the value in the username box?

Or use a sub form and pass the value to it?
Jan 16 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.