Results 1 to 5 of 5

Thread: ADO querying

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    21

    Unhappy ADO querying

    I have a grave problem that is probably simple to fix but not sure if I am seeing it! I am creating a program that I need to search through a table via query and simply list the results (simple enough) - but I can not get things to work. I any one can shed some light on the subject or share some code I would greatly appreciate it.


    Here is what I am doing:

    Form_Load event: (WORKS FINE)

    'Database connection establishment
    Set adoCon = New Connection
    Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & picDB
    adoCon.Open Connect

    Some_Click event: (PROBLEM)

    'Want to query here:

    Set adoRec = New Recordset
    SQLQuery = ""
    SQLQuery = "SELECT PictureAttributes.Photographer FROM PictureAttributes" & _
    " WHERE (((PictureAttributes.Photographer)= SMITH))"

    adoRec.Open SQLQuery, Connect, adOpenDynamic, adLockOptimistic, adCmdText

    'It is here where I am getting this runtime-error:

    Runtime-error '-2147217904(80040e10)'
    No value given from one or more required parameters.


    IF I MAKE SQLQuery THIS:
    SQLQuery = "SELECT PictureAttributes.Photographer FROM PictureAttributes"

    adoRec.Open SQLQuery, Connect, adOpenDynamic, adLockOptimistic, adCmdText

    'I get no errors but I am missing WHERE clause


    If I do this:

    Some_Click event: (PROBLEM)

    'Want to query here:

    Set adoRec = New Recordset
    SQLQuery = ""
    SQLQuery = "SELECT PictureAttributes.Photographer FROM PictureAttributes"

    'Or this SQLQuery

    SQLQuery = "SELECT PictureAttributes.Photographer FROM PictureAttributes" & _
    " WHERE (((PictureAttributes.Photographer)= SMITH))"

    adoRec.Open SQLQuery, Connect, adOpenDynamic, adLockOptimistic, adCmdTable 'Changed from adCmdText

    'Both strings I am getting this runtime-error:

    Runtime-error '-2147217900(80040e14)'
    Syntax error in FROM clause.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    SQLQuery = "SELECT * FROM PictureAttributes" & _
    " WHERE (((PictureAttributes.Photographer)= SMITH))"

    try that and let me know how it goes
    -= a peet post =-

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    one more thing...

    when posting code, use the vbcode tag


    [vbcode]
    MsgBox "u'r code goes here"
    [/vbcode]

    will look Like this

    VB Code:
    1. MsgBox "u'r code goes here"
    -= a peet post =-

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    adoRec.Open SQLQuery, Connect, adOpenDynamic, adLockOptimistic, adCmdTable 'Changed from adCmdText
    Why did you change it from adCmdText to adCmdTable. If you specify adCmdTable then the Source parameter (your SQLQuery variable) must be the name of a valid table.

    It looks like you are just missing some quotes.

    Try this out
    VB Code:
    1. SQLQuery = "SELECT PictureAttributes.Photographer FROM PictureAttributes" & _
    2. " WHERE (((PictureAttributes.Photographer)= [b]'SMITH'[/b]))"
    3.  
    4. adoRec.Open SQLQuery, Connect, adOpenDynamic, adLockOptimistic, adCmdText

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    21
    Peet & Brucevde,

    Thank you for both your help & the helpful hint about posting code. The lengthy SQL string was the problem. Everything seems to work now.

    To answer Brucevde's reply if I leave adCmdTable I get an error
    stating:
    A syntax error in the FROM clause.

    When I changed it to adCmdText - no error I will further experiment.

Posting Permissions

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



Click Here to Expand Forum to Full Width