Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2013
    Posts
    15

    Sql query problem

    i doing one project in vb and access 2003.
    i have a plan to create one query for date search...i have one table and 5 fields(field names is amddate,amddate1,amddate2,total,sample)

    my requirement is ---if i enter one DATE on search field,query checks the 2 date fields(amddate,amddate1) and displays ......

    [example is--if i enter 12/7/2013 on search field query checks the 2 fields(amddate,amddate1),if its true then display]




    regards
    boby

  2. #2
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    What is your "if its true" criteria ? Would it be if amddate = amddate1 and amddate2. And if so you want the SELECT to display in what? Assuming that just a simple query would seem to do the trick tho.

  3. #3
    Join Date
    Jun 2013
    Posts
    15
    thank you for your information, i tried that code but its fail.i also attached error message and code.


    my requirement is ----if i enter any date on (dtpamdsrh.Value),query check the sam and jdate data field.if that date found in sam and jdate,shown in result.. can you please check this...Click image for larger version. 

Name:	error.JPG 
Views:	7 
Size:	61.6 KB 
ID:	12979

  4. #4
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    I think this little wiki might just give you what you need about querying with recordsets : http://www.utteraccess.com/wiki/inde..._for_Beginners

  5. #5
    Join Date
    Jun 2013
    Posts
    15
    if i enter only one field,its working fine.my requirement is checking two fields,i also attached working source code and can you please edit this code for two fields,

    Private Sub search1_Click()
    Set rs4 = New Recordset
    Set rs4 = New Recordset
    rs4.Open "select * from employeeentry where sam = #" & dtpamdsrh.Value & " # ", ds4, adOpenStatic, adLockOptimistic

  6. #6
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    If your code is working for your database for that specific field then :

    rs4.Open "SELECT * FROM employeeentry WHERE sam = #" & dtpamdsrh.Value & "# AND jdate = #" & dtpamdshr.Value & "#" , ds4, adOpenStatic, adLockOptimistic

    Basically you want :
    SELECT * FROM eployeeentry WHERE sam=#date# AND jdate=#date#

    http://www.w3schools.com/sql/sql_and_or.asp

    That being said I would use the CDate() function to do what you are trying to do since you seem to be using a string for your date.

    http://www.techonthenet.com/access/f...type/cdate.php

    Also, I am not an expert at this so sorry if I'm not helping but I'm not too sure about the ", adOpenStatic, adLockOptimistic" part. Does it have to be there? It MIGHT be causing some issues.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query problem
    By lamkee in forum Queries
    Replies: 13
    Last Post: 12-12-2010, 10:30 PM
  2. Query problem
    By puppychew in forum Access
    Replies: 20
    Last Post: 02-01-2010, 09:43 AM
  3. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM
  4. query problem
    By maxx3 in forum Queries
    Replies: 35
    Last Post: 05-29-2009, 04:07 PM
  5. problem with query
    By kiethb in forum Queries
    Replies: 3
    Last Post: 04-24-2009, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums