Open Report from Information in a Form (1 Viewer)

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
Greetings,

I have a Table with Emp_ID and Details of my Employees. I have created a query and set parameter [Enter Emp_ID]. When I pull up a report, I get a pop-up and it asks me for the Emp_ID. When I input same, I get the information I need. Everything is good so far...

My Question... I have designed a report when user will need to enter Emp_ID and click on a button and they will get the report "EMPReport" without having the pop-up window asking for EmpID.

I have been using the below code but I get the pop-up again and I need to enter the Emp_ID again to view the report - Can anyone help me with the coding and let me know where I am wrong.

See below Code:

Code:
Private Sub Image11_Click()

    If IsNull(Me.Emp_ID) Or Me.Emp_ID = "" Then
        MsgBox "You must enter an Emp ID.", vbOKOnly, "Required Data"
        Me.Emp_ID.SetFocus
        Exit Sub
    End If

DoCmd.OpenReport "Rpt_HR1", acViewPreview, , "[Emp_ID]= " & "" & Me!Emp_ID & ""
End Sub
 

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 06:21
Joined
Jul 15, 2008
Messages
2,271
Some ideas you may wish to consider.

Do not use spaces in Field Names and Text Box Control Names - any names. You can use spaces in Captions.

Ensure Text Box Control Names and Control Source are not the same.
eg Control Source is EmpID then Control Name could be txtEmpID.

Your DoCmd code appears in error.
 

ypma

Registered User.
Local time
Today, 19:21
Joined
Apr 13, 2012
Messages
643
Have you tried the whereCondition ? in my code replace my test to report name and id with empid

DoCmd.OpenReport "test", acViewPreview, WhereCondition:="[id] = " & Me.ID & ""
 

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
I tried the above and was not able to get a resolution. It is prompting again for the Emp ID in the Pop-Up...

My Report record source comes from a Qry_List. Name of the Emp_ID in the report is txtEmp_ID and control source is Emp_ID.

In my Form, name of the Text Box is Emp_ID and no control source....
 

ypma

Registered User.
Local time
Today, 19:21
Joined
Apr 13, 2012
Messages
643
Where is your image11 button located ? is it on a form ? My example should work n the form of the record of the id you wish to see in your report .
Is Image11 a text box ?
 
Last edited:

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
I created a form and add a text box. Label name is Employee ID and Text Box Name is Emp_ID with no Control Source. I then added an image on that form and on click, I have added the Event Procedure on Click

Code:
Private Sub Image11_Click()

    If IsNull(Me.Emp_ID) Or Me.Emp_ID = "" Then
        MsgBox "You must enter an Emp ID.", vbOKOnly, "Required Data"
        Me.Emp_ID.SetFocus
        Exit Sub
    End If

DoCmd.OpenReport "Rpt_HR", acViewPreview, WhereCondition:="[Emp_ID] = " & Me.Emp_ID & ""
End Sub
 

ypma

Registered User.
Local time
Today, 19:21
Joined
Apr 13, 2012
Messages
643
I will create a demo for you ,to ensure that I understand the requirement . What version of access suits you /
 

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
I am currently on Access 2007. Here is below what I am doing:

Table:
Emp_ID
Name
Position
DOB
Hire_Date

I created a Query to have the below:
Emp_ID
Name
Position
DOB
Age
Hire_Date
Tenure (Time With the Company)

My Report contains all what i listed in the Query. My report is taken from the query. In my Query, I have set a criteria under Emp_ID to [Enter Emp ID]. Each Time I run the report, I get a pop-up which request an Emp ID.

Now I want to eliminate this and want the Emp_ID to be input in a form. Hence, i created a Blank form and added a Text Box with Label name is Employee ID and Text Box Name is Emp_ID with no Control Source. I have then added a picture with the below event procedure. I want someone just to open the form, input Emp_ID and click on the picture and he/ she will get the all the information in a report which has been designed already.

Your help is much appreciated...

Code:
Private Sub Image11_Click()

    If IsNull(Me.Emp_ID) Or Me.Emp_ID = "" Then
        MsgBox "You must enter an Emp ID.", vbOKOnly, "Required Data"
        Me.Emp_ID.SetFocus
        Exit Sub
    End If

DoCmd.OpenReport "Rpt_HR", acViewPreview, "[Enter Emp ID] = " & Me!EmpID
End Sub
 

ypma

Registered User.
Local time
Today, 19:21
Joined
Apr 13, 2012
Messages
643
There does not appear to an option for me to change my access 2010 to acess 2007 so will send any way . if not i will save as acess 2003 which you will be able to open.

This demo is just that i have not used your control names etc. and also no error procedures .
I have used a command button instead of a Image my preference .
Have a look at it and confirm that i am supply the results you require
 

Attachments

  • DemoOpenRpt.accdb
    592 KB · Views: 85

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
Oops. not able to get that open or transfer that to 2007.

Can someone please convert the attachment to access 2007 and send that back - Thanks!


Regards,

Sunny
 

ypma

Registered User.
Local time
Today, 19:21
Joined
Apr 13, 2012
Messages
643
Sunny Thank you for the feed back , Did you manage to open my demo ?

Regards Bob
 

Sunny Boy 1318

Registered User.
Local time
Today, 22:21
Joined
May 9, 2013
Messages
40
Yes Bob, I managed to open the Database. It is working fine now. Appreciate your help! ;)
 

Users who are viewing this thread

Top Bottom