Answered by:
login form code

Question
-
hi:
i have end user db with connect tables
i did a login form that work good
now what i have to do white this form is to print a report for every one of the workers(to do list)
i need a code that will do the following things
1 go to the report and do a filtering were the name of the worker is sowed by the user name that he logged in
2 print the report
my code so far
Private Sub btnlogin_Click() Dim rs As Recordset Set rs = CurrentDb.OpenRecordset("tblworkers", dbOpenSnapshot, dbReadOnly) rs.FindFirst "username='" & Me.txtusername & "'" If rs.NoMatch Then Me.lblWrongUser.Visible = True Me.txtusername.SetFocus Exit Sub End If Me.lblWrongUser.Visible = False If rs!password <> Nz(Me.txtpassword, "") Then Me.lblwrongpass.Visible = True Me.txtpassword.SetFocus Exit Sub End If End Sub
Monday, June 13, 2016 1:57 PM
Answers
-
So everytime someone log's in you want to print a report? Why not simply log it in a table?
Regardless, to answer your actual question, you'd use code similar to:
DoCmd.OpenReport "ReportName", acViewNormal, , "[username] = '" & Me.txtusername & "'"
Daniel Pineault, 2010-2012 Microsoft MVP
http://www.cardaconsultants.com
MS Access Tips and Code Samples: http://www.devhut.net- Edited by Daniel Pineault (MVP)MVP Monday, June 13, 2016 2:06 PM
- Marked as answer by eshay1 Monday, June 13, 2016 5:09 PM
Monday, June 13, 2016 2:05 PM
All replies
-
So everytime someone log's in you want to print a report? Why not simply log it in a table?
Regardless, to answer your actual question, you'd use code similar to:
DoCmd.OpenReport "ReportName", acViewNormal, , "[username] = '" & Me.txtusername & "'"
Daniel Pineault, 2010-2012 Microsoft MVP
http://www.cardaconsultants.com
MS Access Tips and Code Samples: http://www.devhut.net- Edited by Daniel Pineault (MVP)MVP Monday, June 13, 2016 2:06 PM
- Marked as answer by eshay1 Monday, June 13, 2016 5:09 PM
Monday, June 13, 2016 2:05 PM -
Hi. Pardon me for jumping in... If you think you might intend to use the login form to get the username throughout your database, you could consider using TempVars or "hide" the login form and keep it open in the background. Just a thought...Monday, June 13, 2016 4:18 PM
-
first thank you
i can't do it because the system is for reporting malfunction(brookin doors, locks etc') by the student
so the main form is locked
we can call the login form as print report by password
by the way i have only one report that i'm filtering by the worker name and print
im editing my replay to thank daniel. it work great i just replayed "username" in "fieldname"
here is the full code if it well help someone
Private Sub btnlogin_Click() Dim rs As Recordset Set rs = CurrentDb.OpenRecordset("tblworkers", dbOpenSnapshot, dbReadOnly) rs.FindFirst "username='" & Me.txtusername & "'" If rs.NoMatch Then Me.lblWrongUser.Visible = True Me.txtusername.SetFocus Exit Sub End If Me.lblWrongUser.Visible = False If rs!password <> Nz(Me.txtpassword, "") Then Me.lblwrongpass.Visible = True Me.txtpassword.SetFocus Exit Sub End If DoCmd.OpenReport "report_name", acViewNormal, , "[feild_name in report] = '" & Me.txtusername & "'" DoCmd.Close acForm, Me.Name End Sub
- Edited by eshay1 Monday, June 13, 2016 5:09 PM editing
Monday, June 13, 2016 4:29 PM