Results 1 to 6 of 6
  1. #1
    lookingforK is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2012
    Posts
    31

    Question How to convert Text values in Text Boxes to Integers and use them as parameters?

    Hi,



    I am using Query Design with MS Access 2007 to create a query for selecting/extracting a data set.

    I make 2 text boxes named "Week From" & "Week To" on a form so that when I enter 2 numbers (but with
    Text
    type) in the text boxes and click a button running the query, I would get a selected data set for the specific period.

    For example, when I enter "1" in "Week From" and 8 in "Week To", I should get the data set about the period from Week 1 to Week 8.

    The problem is:
    The data type of the corresponding fields in the table for "Week From" & "Week To" is
    Integer. So, I need to convert the 2 text boxes from Text to Integer or Number
    .

    I try to use the function
    Cint
    (please see below) in the query, but get error message.
    * <=CInt([Forms]![Extract Data]![Week To])

    * >=CInt([Forms]![Extract Data]![Week From])

    Why? How to convert the Text values in Text Boxes and use them as parameters in the query?


    Thank you in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    What is the error message? Why do you show * in the examples?

    Conversion with functions should not be needed. Because the fields are number type the code should do an implicit conversion of the entries and as long as no alpha characters are encountered, should run just fine. Same goes for entering a date into a textbox as criteria for a date field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lookingforK is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2012
    Posts
    31
    Thank you.

    I even tried Forms]![Extract Data]![Week From].[text] or Forms]![Extract Data]![Week From].[value]... Can't work too.

    Looks like only the parameters from combo boxes can work.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    I don't like to use parameterized queries but I did a test prior to my previous post and input from textbox worked just fine.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    lookingforK is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2012
    Posts
    31
    Thank you. Still testing ...

  6. #6
    lookingforK is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2012
    Posts
    31
    I found the cause.

    It works when using the values in Text Boxes as parameters for the query under 1 condition: after I input the values into the 2 Text Boxes, I should left-click the mouse on whatever other place except the 2 Text Boxes.

    I think it is more convenient to use the Combo Boxes ...

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

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2013, 09:53 PM
  2. Option Buttons convert values to text
    By TimMoffy in forum Access
    Replies: 3
    Last Post: 05-21-2012, 07:15 AM
  3. Hve text combo box values but store integers in field
    By accesshelpasker in forum Access
    Replies: 9
    Last Post: 10-28-2011, 10:49 AM
  4. Replies: 10
    Last Post: 12-11-2010, 11:01 PM
  5. Assigning values to Text Boxes
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 12-11-2010, 01:26 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