Results 1 to 3 of 3

Thread: DLookup

  1. #1
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273

    Unanswered: DLookup

    Am I missing something here but the code below, keeps telling me that I have a Syntax Error (missing operator) in query expression 'SchoolName = & Forms!frmInputData!cboSchoolName & '.

    Code:
    Me.txtSchoolCode = DLookup("SchoolCode", "tblSchoolsLkUp", "SchoolName =  & Forms!frmInputData!cboSchoolName & ")
    where have I gone wrong?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if the column is text/string then you need to encapsualte it with " or '
    Me.txtSchoolCode = DLookup("SchoolCode", "tblSchoolsLkUp", "SchoolName = " & chr$(34) & Forms!frmInputData!cboSchoolName & chr$(34) )

    or

    Me.txtSchoolCode = DLookup("SchoolCode", "tblSchoolsLkUp", "SchoolName = '" & Forms!frmInputData!cboSchoolName & "'" )

    whe you struggle with these sort of problems its always worth while assigning the value of your SQl to a variable so you cna check to see what you think you are sending to the SQL engine is the same as is actaully being sent

    eg
    strSQl = "SchoolName = " & chr$(34) & Forms!frmInputData!cboSchoolName & chr$(34) )

    Me.txtSchoolCode = DLookup("SchoolCode", "tblSchoolsLkUp", strSQL)
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273
    Excellent Thanks for that

Posting Permissions

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