Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo boxes, enter value parameter? 1

Status
Not open for further replies.

detdu

Technical User
Joined
May 23, 2003
Messages
36
Location
SE
Hi.. I tried to make two combo boxes with one command button that will run a query and then show the results that i chose in the combo boxes on a report... but when i klick the command button a dialog shows that says "enter value parameter"... i dont know what ive done wrong cause im very new at this.. therefore i would be glad for all the help i can get... the code is;

Private Sub runquery_Click()
On Error GoTo Err_runquery_Click

' set up constants and variables

Dim WClause As String
Const Rview = "acViewPreview"
Const SView = "SelectRelations" ' this is a query

' I am using a query to combine results
' from two linked tables

Const RName = "Reportname"
' this is a report
' get the parameters from the combo boxes
WClause = "[SelectRelations].[Country] = '" & Me.CountryCombo & _
"' AND [SelectRelations].[Event] = '" & Me.EventCombo & "'"

' Open the report in preview mode
DoCmd.OpenReport _
Reportname:=RName, _
View:=acViewPreview, _
Filtername:=SView, _
WhereCondition:=WClause

Exit_runquery_Click:
Exit Sub

Err_runquery_Click:
MsgBox Err.Description
Resume Exit_runquery_Click
End Sub


the sql code in the combo boxes are
SELECT DISTINCTROW [tblCountry].[CountryID], [tblCountry].[Country] FROM tblCountry ORDER BY [Country];
and the same with the city...

what can be wrong?
 
Normaly when you recieve an "enter value parameter" you have a parameter on the query you are calling.

Open the query in design, right click and choose parameter.

Rgds
Herman
 
thanks alot.. i will try that :)
 
can u help me with another thing... if i use tab.. and create two combo boxes on the first page and two o nthe second... and i want to use them all when i filter to show my information on a report... is it anything specific that i have to think about and change?
 
I have a few places where I use something similar to what you are trying to do.
I have overview-forms that in turn will find a specific client for me, I use this function to gather the string that I need:

Function Vis_Kunder(F_DebitorID, F_Firma, F_Navn, F_Adresse, F_PostNr, F_GRUPPE)
Dim MySql As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
Dim Tmp As Variant

If Not IsLoaded("Kundeoversigt") Then
DoCmd.OpenForm "Kundeoversigt", acNormal
If IsNull(F_DebitorID) Or F_DebitorID = "" Then Exit Function
End If

ArgCount = 1
DoCmd.Close A_FORM, "Debitorkort"
DoCmd.Close A_FORM, "Debitor"
MySql = "SELECT DebitorID , [FIRMA] & ' ' & [Navn] & ', ' & [Adresse] & ', ' & [Debitor].[PostNr] & ' ' & [Bynavn] AS NavnAdresse, Debitor.[Tlf] FROM Debitor LEFT JOIN Postnr ON Debitor.Postnr = Postnr.PostNr WHERE "

MyCriteria = "FirmaID = '" & Forms!Ekspedition!FirmaID & "' "
AddToWhere F_DebitorID, "[DebitorID]", MyCriteria, ArgCount, "Like"
AddToWhere F_Firma, "[FIRMA]", MyCriteria, ArgCount, "Like"
AddToWhere F_Navn, "[NAVN]", MyCriteria, ArgCount, "Like"
AddToWhere F_Adresse, "[Adresse]", MyCriteria, ArgCount, "Like"
AddToWhere F_PostNr, "[Debitor].[PostNr]", MyCriteria, ArgCount, "Like"
AddToWhere F_GRUPPE, "[GRUPPE]", MyCriteria, ArgCount, "Like"

If MyCriteria = "" Then MyCriteria = "True"

MyRecordSource = MySql & MyCriteria
Forms!Kundeoversigt!Criteria = MyCriteria
Forms!Kundeoversigt.RecordSource = MyRecordSource
If Forms!Kundeoversigt.RecordsetClone.RecordCount > 0 Then Forms!Kundeoversigt![F_DebitorID].SetFocus
End Function

All the "F_" fields are ref to fiels names/combo boxes on the form from where I call this function. Also you will need this function to match what you are looking for:

Sub AddToWhere(Field_Value As Variant, FieldName As String, MyCriteria As String, ArgCount As Integer, Argument As String)
Dim ChrStr

If IsNull(Field_Value) Then Exit Sub
If Field_Value = "" Then Exit Sub

ChrStr = Left(Field_Value, 1)

If (ChrStr = &quot;'&quot;) Or (ChrStr = &quot;#&quot;) Then If Len(Field_Value) < 3 Then Exit Sub

If Field_Value <> &quot;&quot; Then
If ArgCount > 0 Then MyCriteria = MyCriteria & &quot; and &quot;

If Argument = &quot;Like&quot; Then
MyCriteria = (MyCriteria & FieldName & &quot; Like &quot; & Chr(39) & Field_Value & Chr(42) & Chr(42) & Chr(39))
Else
MyCriteria = (MyCriteria & FieldName & &quot; &quot; & Argument & &quot; &quot; & Field_Value)
End If
ArgCount = ArgCount + 1
End If
End Sub
Let me know how it goes.

Herman
 
thanks for the codes and explanation.. but since im very new at this and dont really know what to put where... its kind of complicated for me... i understand some stuf but still.. dont know where to put the codes :/ thanks alot though
 
fundis81@hotmail.com

thanks alot :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top