Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2003
    Posts
    42

    Unanswered: Help needed with passing 2 parameters

    How exactly do you write the code below to pass 2 parameters at the same time?

    ChargeRate = DLookup("[FlatRate]", "Charges", "[ChargeDescription]= cboChargingScheme.Text")

    Any help would be very much appreciated. Thanks!

  2. #2
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    If you are talking about the 'where' part of the DLookup, try this...

    ChargeRate = DLookup("[FlatRate]", "Charges", _
    "[ChargeDescription]= '" & cboChargingScheme.Text & "'")

    Remember to use single quotes around text values.
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  3. #3
    Join Date
    Dec 2003
    Posts
    42
    Unfortunately, that isn't the answer I needed.

    What I have is...

    ChargeRate = DLookup("[FlatRate]", "Charges", "[ChargeDescription]= cboChargingScheme.Text")

    And I need to pass 2 parameters, something like this...

    ChargeRate = DLookup("[FlatRate]", "Charges", "[ChargeDescription, CarCategory]= cboChargingScheme.Text, txtCarCategory.Text")

    Unfortunately, that is wrong and doesn't work, but that is the sort of thing I need!! Please help!!!!

  4. #4
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Jpshay has you started.

    To add another parameter, use AND:

    ChargeRate = DLookup("[FlatRate]", "Charges", _
    "[ChargeDescription]= '" & cboChargingScheme.Text & "' AND [CarCategory] = '" & txtCarCategory.Text & "'")
    All code ADO/ADOX unless otherwise specified.
    Mike.

  5. #5
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    ChargeRate = DLookup("[FlatRate]", "Charges", _
    "[ChargeDescription]= '" & me.cboChargingScheme.Text & "'" & _
    " AND [CarCategory] = "'" & me.txtCarCategory.Text & "'")

    That should work jest fine, if both controls contain text.

    by the way, fiddling with a query in design mode, and then examing the SQL statement that Access generates can help you in the future.
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  6. #6
    Join Date
    Dec 2003
    Posts
    42
    Thanks guys, I get an error though that says...

    'You cant reference an object unless it has the focus'

    And you can't set the focus on 2 items at once, so I am totally stuck!

  7. #7
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Actually, I rarely use the .Text property. I use .Value and don't seem to run into this problem.

    What is ChargeRate? A variable or a control?
    All code ADO/ADOX unless otherwise specified.
    Mike.

  8. #8
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    Sorry, I didn't even notice that part of the parameter. Like Mike, I rarely use the .Text property or even the .value. I suggest you leave them off.
    Strip the code down as follows.

    ChargeRate = DLookup("[FlatRate]", "Charges", _
    "[ChargeDescription]= '" & me.cboChargingScheme & "'" & _
    " AND [CarCategory] = "'" & me.txtCarCategory & "'")

    Let me know if there are any other questions.
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •