how to open report from msgbox with a condition

basilyos

Registered User.
Local time
Today, 03:44
Joined
Jan 13, 2014
Messages
256
good evening every one

i have a form to enter a new client if the client is existed then a message box appear and tell me that this client is existed and his number id is ## with two buttons yes and no
if i click yes i should go to a report that contains information about that user
and this report take his data from a query



new client save code
---------------------
Dim MSG As Integer
Dim ExistentID As Long
ExistentID = Nz(DLookup("P_ID", "tbl_Personal_Information", "Full_Name = Forms!frm_New_Person!F_N"), 0)
If ExistentID > 0 Then
'--------------------------
MSG1 = MsgBox("this client is existed and his id number is {" & [ExistentID] & "}, do you want to see his information ", vbYesNo + vbQuestion + vbMsgBoxRtlReading, "client database")
If MSG1 = vbYes Then
DoCmd.OpenReport "rpt_personal_information", acViewPreview, , "[PIDDD] = " & [ExistentID]
Else
End If
Else
strsql101 = "insert into tbl_Personal_Information (Name_English, Father_English, Family_English, Mother_English, P_ID, NName, Father, Family, Mother, Birthdate, Nationality, Record_Number, Record_Place, Address, Mobile1, Mobile2, Phone1, Phone2, Ets_Name) Values ('" & Me.Name_English & "','" & Me.Father_English & "','" & Me.Family_English & "','" & Me.Mother_English & "','" & Me.PID & "','" & Me.NName & "','" & Me.Father & "','" & Me.Family & "','" & Me.Mother & "','" & Me.Birthdate & "','" & Me.Nationality & "','" & Me.Record_Number & "','" & Me.Record_Place & "','" & Me.Address & "','" & Me.Mobile_1 & "', '" & Me.Mobile_2 & "','" & Me.Phone_1 & "', '" & Me.Phone_2 & "','" & Me.Ets_Name & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql101
'--------------------------
MSG2 = MsgBox("information added succesfully, do you want to add a new record", vbYesNo + vbQuestion + vbMsgBoxRtlReading, "client database")
If MSG2 = vbYes Then
DoCmd.Close acForm, "frm_New_Person"
DoCmd.OpenForm "frm_New_Person"
Else
DoCmd.OpenForm "frm_Entering_Data"
DoCmd.Close acForm, "frm_New_Person"
End If
End If




note that PIDDD is a textbox in the report that it's bounded with P_ID in the query


my problem is this line
DoCmd.OpenReport "rpt_personal_information", acViewPreview, , "[PIDDD] = " & [ExistentID]

when i click yes the report should open with the existent id but he open a input box to ente an id and his title is tbl_personal_information.PID it's the ID field that it's named P_ID in the query
 
When you are using the filter option of OpenReport, you must refer to the underlying recordsource. Not the control name.

Try:
Code:
DoCmd.OpenReport "rpt_personal_information", acViewPreview, , "[P_ID] = " & [ExistentID]
 
same problem

input dialog with title tbl_personal_information.PID
 
This indicates that somewhere on your report there is a control with a controlsource that the system does not recognize.

Try opening the report by itself and you should receive the same error.

You will need to change the controlsource of the erroneous control to match the underlying recordsource
 
thank you bro it works
i was making a group in my report by fault when i delete it everything is ok
 

Users who are viewing this thread

Back
Top Bottom