 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 24th, 2008, 09:19 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
need help
I have Login form it is related to table login. In table login lngEmpID(PK),username,Password fields
In Logon form cmdLogin click event is like below
Private Sub cmdLogin_Click()
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "rptATC"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
End Sub
Now I want show user name in ârptATCâ which user created this report. So what I want to do
Mohamed Mohiddin
Officer
__________________
Mohamed Mohiddin
Officer
|
|

October 28th, 2008, 10:19 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Assuming the form being opened has a field named txtUserID, I'd write the valid password portion as follows:
----------------------------------------------------------
lngMyEmpID = Me.cboEmployee.Value
DoCmd.OpenForm "rptATC"
Forms("rptATC").txtUserID.value = Me.cboEmployee
DoCmd.Close acForm, "frmLogon", acSaveNo
----------------------------------------------------------
Note that I move the form close to be at the end. When having a form close itself it should be the last thing you do.
One other helpful little hint. You have several comparisons that start like:
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" then
I use this little trick instead:
If Me.cboEmployee.value & "" = "" then
I also usually put in the .value instead of assuming it.
|
|

October 28th, 2008, 04:03 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks allenm for reply
But what event i want to do your post the code
Actively I want user name in form ârptATCâ in header section
eg.like
This Report created by i want particular usename in header section
pleace help me
Mohamed Mohiddin
Officer
|
|

October 29th, 2008, 11:10 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I can help with putting the name in the header.
Create a module, and in that module create a public variable
Public sUserName As String
Then put the username that you capture in your code in the public variable.
Then on the On Format event of your report header, create a text box, no label, and put this:
If sUserName <> "" Then
Me.Textbox = "This Report created by " & sUserName
Else
Me.Textbox = "User information was not captured"
End If
Did that help?
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

October 30th, 2008, 01:47 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you mmcdonal for reply
i create a module as sUserName but Compile error show Type mismatch
what is wrong with me
Mohamed Mohiddin
Officer
|
|

October 30th, 2008, 07:26 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
What did you name the module? You can name it Module1, for example.
Then within the module, put this line:
Public sUserName As String
That is a string variable. Then how do you capture the name and put it into that string? What code do you use when you launch the report?
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

October 30th, 2008, 11:52 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks once again, i create a module as you says module1
i put code Public sUserName As String
but now show value like This Report created by 1 or 2
Actively I want user name like a,b,c which name in tblEmplyee
Mohamed Mohiddin
Officer
|
|

October 30th, 2008, 12:11 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I see. So when you take the employee information, you are only taking the ID number of the record, not the employee's name. In that case, you would need to either take the name from the form, or, using the ID, look up the person's name from the table. Can you do that?
If the form has these fields, EmployeeID, FristName, LastName, for example, then you would use this:
sUserName = Me.FirstName & " " & Me.LastName
Then on the on format event of the report header:
Me.Textbox = "This Report created by " & sUserName
Will that work for you? If the names are not on the form, then you will need to add a step where you look up to tblEmployee with the ID and take the name from the recordset.
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|
 |