Results 1 to 5 of 5

Thread: Input box on query

  1. #1
    Junior Member
    Join Date
    Jan 12
    Posts
    18

    Input box on query

    Hi

    I'm trying to get a query to handle a input box like so:

    Code:
    'input box for w/c
    
    inputdate = InputBox(Prompt:="Enter Mondays date", Title:="date Input")
    
    
        
        
    'SET DB AND FIELDS
    
    Set db = CurrentDb
        
    'Set rs = db.OpenRecordset("SELECT * FROM tbl_Schedule WHERE (((tbl_Schedule.Date)='& inputdate &'))")


    I notice that the query works in this format:

    Code:
     Set rs = db.OpenRecordset("SELECT * FROM chaseupEmail WHERE (((chaseupEmail.Date)=#14-may-12#))")
    But when I enter the date 14-may-12 in the input box, the query does not recognise the date.

    Any help would be greatly appreciated
    Matt
    Twitter @dancematt

    Programmers unite

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    Re: Input box on query

    But when I enter the date 14-may-12 in the input box, the query does not recognise the date.
    you would need to validate the date and make sure it is the correct format for the database
    access must be mm/dd/yyyy, regardless of your locale
    also as you can see dates should be enclose in # rather than '
    so your query should look like
    vb Code:
    1. rs = db.OpenRecordset("SELECT * FROM tbl_Schedule WHERE (((tbl_Schedule.Date)=#" & inputdate & "#))")
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,655

    Re: Input box on query

    It WOULD recognize it if you put # delimiters around it.... right now your query looks like this:
    WHERE (((tbl_Schedule.Date)='& inputdate &'))")

    Actually there's two things wrong... first no date delimiters (#) and secondly since you used single tick marks, you inserted the string literal & inputdate & into your query... it should look like this:


    WHERE (((tbl_Schedule.Date)=#" & inputdate & "#))")


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  4. #4
    Junior Member
    Join Date
    Jan 12
    Posts
    18

    Re: Input box on query

    you my friend, are a hero

    thank you very much
    Twitter @dancematt

    Programmers unite

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,655

    Re: Input box on query

    if your issue has been resolved, please mark the thread resolved. You can do this by using the Mark as Resolved menu item under the Thread Tools at the top of post 1.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

Posting Permissions

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