Re: Dlookup with 2 criteria



Thanks. both of them are text fields. how should i change my code?



"Marshall Barton" wrote:

> Michelle K wrote:
> >I am trying to prefill a textbox (txtBudget) with the budget value found in
> >the testquery table. I have two criteria : cost code and category which are
> >both filled in using combo boxes (cboCC and cboCat).
> >
> >I'm trying the cboCat afterupdate procedure to update the textbox but my
> >code isn't working. help! thanks a lot.
> >
> >here is the code:
> >
> >Private Sub cboCat_AfterUpdate()
> >
> >Dim CC As String
> >Dim Cat As String
> >Dim result
> >
> >CC = cboCC.Value
> >Cat = cboCat.Value
> >
> >result = DLookup("[Total_Estimate]", "[testquery]", "[Cost_Code]= ' " & CC &
> >" ' and [Category] = " & Cat)
> >
> >txtBudget.Value = result
> >End Sub
>
>
> Apparently the Cost_Code field is a text field and Category
> is a numeric field. If that true, then the only thing I see
> wrong is the extra spaces between the quotes and
> apostrophes.
>
> To avoid potential errors, you may want to add more code to
> check that the two combo boxes actually have a value:
>
> If Nz(Me.cboCC, "") = "" OR Nz(cboCat, "") = "" Then
> Exit Sub
> End If
>
> --
> Marsh
> MVP [MS Access]
>
.



Relevant Pages

  • Re: Playing AVI and MPEG using MCI
    ... "mciSendStringA" (ByVal lpstrCommand As String, ... Dim mlRet As Long ... Private Sub CenterObject ... If mlRet 0 Then ...
    (microsoft.public.vb.controls)
  • Change this Program
    ... Private sPathFrom As String ... Private Sub enableControl ... Dim oColor As OLE_COLOR ... Dim sPathTo As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Error when running vb app with FlexGrid control
    ... Private Sub cmdNetChange_Click ... On Error GoTo Command1_Click_Error ... Private Sub fnGetData(strParam0 As String, strParam1 As String, FLX As ... Dim rsADOObject As Recordset ...
    (microsoft.public.vb.general.discussion)
  • Sum in a dynamic query
    ... Private Sub Form_Open ... Dim db As Database, Tbl As TableDef ... Dim db As Database, qd As QueryDef, ctl As Control, s As String, Item As ...
    (comp.databases.ms-access)
  • Re: How to add/load records to combobox ?
    ... Dim rsCustomers As New ADODB.Recordset ... Private msCustomerIDsAs String ... Private Sub Combo1_Click ... Dim sSQL As String ...
    (microsoft.public.vb.controls)