Hvis du har værdien id gemt i en variabel i Visual Basic, kan du bare lade kommandoknappen åbne rapporten. I forespørgslen, under kriterier for id, angiver du en Visual Basic funktion, f.eks. idFunc. Denne funktion skal blot returnere værdien af variablen, som indeholder dit id, denne kunne f.eks. hedde idVar - koden for funktionen ville så være, idet jeg går ud fra, at id er et tal:
Public Function idFunc As Long idFunc = idVar End Function
Okay, lyder rimeligt nok, men hvordan (og hvor) laver jeg så variablen i VB?
Jeg kunne f.eks. godt tænke mig at den kunne udskrive den aktuelle post, altså på en eller anden måde hente id\'et fra et felt (som vises i formularen).
Nu har du tildelt \'idVar\' værdien i dit tekstfelt. Derefter åbner du rapporten. Når rapporten åbnes, køres forespørgslen, som automatisk kører funktionen. Funktionen returnerer så værdien af idVar til forespørgslen.
juggalo> You can place a buutin on a from and then add a buuton using the wizard. You can then add one or more text boxes or combos for entering the information you want the report to show. Then alter the code so that it looks like this, you will need to alter the field names as necessary and also the report name.
Dim stDocName As String Dim sFilter As String
sFilter = \"1 \"
If Not fldIsEmpty(Me.cboBy) Then sFilter = sFilter & \" AND TownID = \" & Me.cboBy End If
If Not fldIsEmpty(Me.txtYear) Then sFilter = sFilter & \" AND årstal = \" & Me.txtYear
In the example I have a text box and a combo box. I can enter information into any of the fields. When the button to print the report is pressed I check to see if data has been entered, if so I build a filter for the report.
juggalo> In the answer that I gave you will need to remove the dialog box which opens for entering your ID, all this is done through the form now. The report now filteres out what you want. If you use the query in other forms and reports then you will need to make a copy of it.
fdata> am I not right in saying that if he does that and doesnt eneter data IE Forms!Formularnavn!Feltnavn = \"\" then it sgoing to look for those that are \"\"?
>Terry You\'re right, but as he wrote: \"Jeg kunne f.eks. godt tænke mig at den kunne udskrive den aktuelle post, altså på en eller anden måde hente id\'et fra et felt (som vises i formularen)\" I assumed that the field was valid.
If that is not the case a simple If IsNull(Me.Feltnavn) then Exit Sub in the buttons OnClick of course would do the job.
Again assuming that all values are valid he just repeats the pattern in the query.
Yes, I know: \"How do we handle combinations of empty and non-empty fields?\" I don\'t think that this is the case for juggalo. Should I be proven wrong - then (you win again) a filter would be a neat solution.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.