Results 1 to 6 of 6
  1. #1
    Max2413 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    9

    Using SQL with an unbound Text Box

    Good evening,

    I am working on my inventory tracking system that keeps a record of items removed from the inventory by scanning a bar code with a scanner that automatically sends a carriage return after a scan (hits enter). So I am using the "on Enter" event to write my code.

    I would like to simply use the SQL "INSERT INTO" statement. I am usinf an unbound text box as input. Here is what I have so far:



    Code:
    Private Sub scanTextBox_Enter()
        Dim StrSQL As String
        Dim scannedCode As String
        
        scannedCode = scanTextBox.Value
        
        StrSQL = "INSERT INTO [Current Sales] ([Purchase Date], [Purchase Time], [Product Code]) VALUES (Date(), Time(), scannedText)"
        
        DoCmd.SetWarnings False
        DoCmd.RunSQL (StrSQL)
        scanTextBox.Value = ""
        DoCmd.SetWarnings True
        
        
    End Sub

    Any advice?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This line:

    StrSQL = "INSERT INTO [Current Sales] ([Purchase Date], [Purchase Time], [Product Code]) VALUES (Date(), Time(), scannedText)"


    ...has at least one problem. What do you think is in scannedText?


  3. #3
    Max2413 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    9
    I started with the txtBox.Text This is returns the formatted string in the box while it has focus right?

    So I started with that, and I was having issues so I tried the .value. That of course is wrong because it returns the default property. Which should be an empty string?

    So with using the .text call I still have a problem with getting through a whole cycle.

    I can enter text, hit enter, and it highlights the text but dosnt write the new record, so i go to design view, and back to form view, click the text box and it prompts for a parameter value.

    Thank you for the not just correcting my code, but questioning it, and please continue to do so.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I think you may have misunderstood what the "On enter" event is - it has nothing to do with the user pressing "Enter". The "On enter" fires as soon as the cursor enters the field (or the user clicks on it)

    I think you want to use the "After Update" event instead.

  5. #5
    Max2413 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    9
    Wow, how dumb. Strange that I built a version 1 of this program and used the macro builder and it still runs completly through the on enter event... weird. You are right though. I will move things around!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Let us know if it is still an issue.

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

Similar Threads

  1. Add unbound text box
    By BWGreen in forum Forms
    Replies: 4
    Last Post: 05-21-2014, 06:24 AM
  2. Information text on unbound text box
    By randle in forum Forms
    Replies: 3
    Last Post: 06-28-2013, 11:43 AM
  3. Replies: 2
    Last Post: 06-11-2012, 09:37 AM
  4. Unbound Text
    By cbrsix in forum Reports
    Replies: 16
    Last Post: 10-27-2011, 01:27 PM
  5. Unbound text box truncating text
    By gddrew in forum Forms
    Replies: 0
    Last Post: 03-02-2006, 11: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