473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

getting user name and insert query

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
8 2145
willakawill
1,646 1GB
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
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
648 Expert 512MB
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
willakawill
1,646 1GB
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
8,834 Expert 8TB
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
648 Expert 512MB
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
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
648 Expert 512MB
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

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

Similar topics

2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
0
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid...
11
by: Jan | last post by:
I'd like a maketable query listing ClientID, and E-mail from another table. This is simple, BUT I'd only like to get only the part after @ in the E-mail. How would this work in MS Access 2003?
2
by: M | last post by:
If I have a query I am writing, I can use the top 10 function to bring back the top 10 rows. That's all fine if all I want is 10 rows. What if I have a grouped query, and I have 5 entities that...
9
by: phopman | last post by:
Hello! I am currently working on a project. And have been assigned to get up to speed quickly on php. And even though I love the language, it's not easy to get up to speed in like 2 seconds :-) ...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
9
by: KDawg44 | last post by:
Hi, I have PHP function that adds a record to the database. The table has an ID that is AUTO_INCREMENT. Is there anyway to get that ID back when I do any kind of insert? That ID is a foreign...
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
9
by: happyse27 | last post by:
Hi All, In perl script(item b below) where we check if html registration form are filled in properly without blank with the necessary fields, how to prompt users that the field are incomplete...
0
by: srig | last post by:
hi all, i hav created a webpart for inserting a record in asp.net ,c# and deploy it in sharepoint.. my code is executing properly.. when i deploy it it asks for insert new record and wen i get the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.