Results 1 to 4 of 4
  1. #1
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60

    Changing to text format

    Ok, I have a code that I use for a different module. This module has a filter based on an input box. The input box appears to be based on a number, and I need it to be based on a text.

    Dim lngColumn As Long
    Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
    Dim dbs As DAO.Database
    Dim rs As DAO.Recordset
    Dim blnEXCEL As Boolean, blnHeaderRow As Boolean
    Dim RFQNUM As String
    RFQNUM = InputBox("Enter RFQ Number")

    The problem is I later use this to run the query. Engine_ID is a text field. RFQNUM appears to be based on a number.

    Set rs = CurrentDb.OpenRecordset("SELECT Year FROM Main_Export WHERE Engine_ID=" & RFQNUM)



    I hope im explaining this ok.

    I am also wanting to select more results. Would I say

    ("Select Year, Field 2, Field 3 FROM"

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Text variables need to be wrapped in single quotes:
    Code:
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM Main_Export WHERE Engine_ID='" & RFQNUM & "'") ' select all fields from the table
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    How many records returned to the rs? ID usually suggests there would be only one. If so, declaring and creating a recordset for one record is overkill - especially since the rs only contains one field. I'd use DLookup, and I would refrain from using reserved words for field names - especially when they are function names (like "Year"). If you were being forced to use such a word, you must enclose them in brackets ( e.g. [Year]). I cannot see how that sql (in post 1) would ever run without generating an error.
    Last edited by Micron; 12-10-2021 at 03:44 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60
    Worked! Thank you!

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

Similar Threads

  1. Changing date format in recordset
    By davideitaly in forum Programming
    Replies: 6
    Last Post: 04-11-2018, 08:45 AM
  2. Replies: 3
    Last Post: 12-30-2016, 10:27 AM
  3. Changing Formatting of Text Values - Accounting Format
    By accessnewbie352 in forum Forms
    Replies: 10
    Last Post: 01-09-2015, 04:42 PM
  4. Changing a Field Format
    By lwinford in forum Forms
    Replies: 3
    Last Post: 04-23-2013, 01:18 PM
  5. Query changing format
    By John Southern in forum Queries
    Replies: 3
    Last Post: 07-05-2010, 09:57 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