zafridi
asked on
using drop down from ms access to get a crystal report
hi experts,
i have a form in ms access that has a drop down menu(account_id). i want to be able to select one account_id from the drop down and it shud open up a crystal report based on that id. i know i have to make a parameter account_id in the report which i already. im just not sure how integrate it with access. Here is my existing code which just opens a whole report when i click on a button. can plz someone give me the code. thanks.
Option Compare Database
Public crxapplication As New CRAXDRT.Application
Public crxreport As CRAXDRT.Report
Private Sub Form_Load()
'Maximizes the form
DoCmd.Maximize
Me!CrystalActiveXReportVie wer1.Top = 600
Me!CrystalActiveXReportVie wer1.Left = 800
Me!CrystalActiveXReportVie wer1.Heigh t = 8000
Me!CrystalActiveXReportVie wer1.Width = 12000
Set crxreport = crxapplication.OpenReport( "C:\report 1.rpt")
CrystalActiveXReportViewer 1.ReportSo urce = crxreport
CrystalActiveXReportViewer 1.ViewRepo rt
CrystalActiveXReportViewer 1.Zoom (100)
End Sub
i have a form in ms access that has a drop down menu(account_id). i want to be able to select one account_id from the drop down and it shud open up a crystal report based on that id. i know i have to make a parameter account_id in the report which i already. im just not sure how integrate it with access. Here is my existing code which just opens a whole report when i click on a button. can plz someone give me the code. thanks.
Option Compare Database
Public crxapplication As New CRAXDRT.Application
Public crxreport As CRAXDRT.Report
Private Sub Form_Load()
'Maximizes the form
DoCmd.Maximize
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
Set crxreport = crxapplication.OpenReport(
CrystalActiveXReportViewer
CrystalActiveXReportViewer
CrystalActiveXReportViewer
End Sub
ASKER
sorry being a pain but can u elaborate on it a little more..im really new to this thing..my dropdown name is ( accountid ) and the parameter in crystal is ( ?account_id ) and its a string..how do i code it..thanks a lot for ur help
Try this
crxreport.RecordSelectionF ormula = "{?account_id} = '" & accountid.Text & "'"
mlmcc
crxreport.RecordSelectionF
mlmcc
ASKER
I tried what u suggested but its giving me "object required" error. i added the line u suggested. thanks for ur help. i really need to get this thing done so please if u can help me out i wud really appreciate. thanks
Option Compare Database
Option Explicit
Public crxapplication As New CRAXDRT.Application
Public crxreport As CRAXDRT.Report
Private Sub Form_Load()
'Maximizes the form
DoCmd.Maximize
Me!CrystalActiveXReportVie wer1.Top = 600
Me!CrystalActiveXReportVie wer1.Left = 800
Me!CrystalActiveXReportVie wer1.Heigh t = 8000
Me!CrystalActiveXReportVie wer1.Width = 12000
crxreport.RecordSelectionF ormula = "{?account_parent} = '" & DAccountParent.Text & "'"
Set crxreport = crxapplication.OpenReport( "C:\schedu le3b.rpt")
CrystalActiveXReportViewer 1.ReportSo urce = crxreport
CrystalActiveXReportViewer 1.ViewRepo rt
CrystalActiveXReportViewer 1.Zoom (100)
End Sub
Option Compare Database
Option Explicit
Public crxapplication As New CRAXDRT.Application
Public crxreport As CRAXDRT.Report
Private Sub Form_Load()
'Maximizes the form
DoCmd.Maximize
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
Me!CrystalActiveXReportVie
crxreport.RecordSelectionF
Set crxreport = crxapplication.OpenReport(
CrystalActiveXReportViewer
CrystalActiveXReportViewer
CrystalActiveXReportViewer
End Sub
Put the line after you initialize the report object.
Move it down after the SET statement
mlmcc
Move it down after the SET statement
mlmcc
ASKER
i did that as well. its telling me the same thing "object required". the way i have it set up is tat i have a drop down i select one account and then i have a button viewreport which shud open the report for selected account..do i need to have some sort of reference to that button as well. thanks for baring with me..
Try this
Change
crxreport.RecordSelectionF ormula = "{?account_parent} = '" & DAccountParent.Text & "'"
to
crxreport.RecordSelectionF ormula = "{?account_parent} = 'xxx' "
where xxx is a known account parent
Do you get the report you expect?
mlmcc
Change
crxreport.RecordSelectionF
to
crxreport.RecordSelectionF
where xxx is a known account parent
Do you get the report you expect?
mlmcc
ASKER
crxreport.RecordSelectionF ormula = "{?account_parent} = '020701032006' " ...i tried this..but im not sure do i need to have a select expert pointing to the account_parent parameter..the problem is i dont want it to open the pop up window from crystal where it asks u for som value..In either case for some reason crystal is not taking in this value from VBA..im not getting any error but when i click on view report its asking me to enter the account number. im not sure what the remedy would be. thanks
ASKER
crxreport.ParameterFields. GetItemByN ame("accou nt_parent" ).AddCurre ntValue "020707271084"..... i tried this and it worked for me. my only problem now is that i wana be able to get a value from the drop down which i tried ur way but didnt work. i wana be able to select an account from the drop down and then click on a command button..u think there need to be some sort of reference between the command button and drop down. any suggestions. thanks for ur help..
Sorry about the confusion. The line should have used your account field not the parameter.
Change
crxreport.ParameterFields. GetItemByN ame("accou nt_parent" ).AddCurre ntValue "020707271084".....
to
crxreport.ParameterFields. GetItemByN ame("accou nt_parent" ).AddCurre ntValue YourDropDown.Text
mlmcc
Change
crxreport.ParameterFields.
to
crxreport.ParameterFields.
mlmcc
ASKER
I changed it to
crxreport.ParameterFields. GetItemByN ame("accou nt_parent" ).AddCurre ntValue DParentAccounts.Text
where DParentAccounts is my dropdown name..its give me error "object required". any suggestions..thanks
crxreport.ParameterFields.
where DParentAccounts is my dropdown name..its give me error "object required". any suggestions..thanks
Is this code on the form with the dropdown? If not you have to fully qualify the name.
Forms!MyForm!DParentAccoun ts.Text
mlmcc
Forms!MyForm!DParentAccoun
mlmcc
ASKER
no its on the seperate form. the combo is on a separate form. thanks
ASKER
crxreport.ParameterFields. GetItemByN ame("accou nt_sub").A ddCurrentV alue Forms!perac!DParentAccount s.Text
i modified it to the above..it just opens a blank viewer..no records on it. im not sure watelse to do with it.
i modified it to the above..it just opens a blank viewer..no records on it. im not sure watelse to do with it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey thanks for all ur help. Actually i figured it out the actual syntax that worked for me is the following.
crxreport.ParameterFields. GetItemByN ame("Field Name").Add CurrentVal ue Forms![FormName]![ComboBox Name].Valu e
Im sure there's probably other ways of doing it but this one worked for me. thanks
crxreport.ParameterFields.
Im sure there's probably other ways of doing it but this one worked for me. thanks
Glad i could help
mlmcc
mlmcc
if AccoutnId is a string
crxreport.RecordSelectionF
If it is a number
crxreport.RecordSelectionF
Change to use your field name and your drop down box
Put it just before the Report Source assignment
mlmcc