Results 1 to 8 of 8
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    Unbound Form updating table VBA

    I have an unbound, no record source form with a few dropdown boxes populated by various tables. The user selects what they want from the dropDown boxes and then clicks a button and my VBA creates a folder in windows with the names from the dropDown boxes as the windows Path. All of this works fine.
    The issue is that I want to store the string created by the multiple dropboxes into a table and this is where my issue resides. I have this, and it does not work.
    CurrentDb.Execute "UPDATE Products SET PhotoDirectory = testing WHERE [ProductCode]=" & "'" & [cmboNames] & "'"
    I want this line to go to my Products Table and insert the word "testing" in the PhotoDirectory field where the product code selected on my unbound form is the same as the product code in the Products Table.
    Thank you for your help with this, and any solution is welcomed even if it is on a different path then the one I am on.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    reference the combo box on the form:

    ="UPDATE Products SET PhotoDirectory = 'testing' WHERE [ProductCode]='" & me.cmboNames & "'"

    this statement says the ProductCode is a string, so
    be sure the cmboNames BOUND COLUMN property is correct

    photoDirectory is a string too, so put quotes around it.


  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    The update is now creating and storing data, thanks.

    The new issue is for SET photoDirectory = 'testing'
    what I really need is basically this:
    Dim strFolderPath As String
    strFolderPath = [cmboDirPath]

    SET photoDirecotory = strFolderPath

    If I say msgBox strFolderPath I get the correct data, but when I put the variable name in the UPDATE line I get blanks.
    How do I go about fixing that?
    Thanks.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Put your sql into a string variable and debug.print it.
    When you get it working, use that variable in your Execute command.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    sorry, but I don't undertand that, can I see an example of this in action?
    thanks.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Code:
    Dim strSQL As String
    StrSQL =  "UPDATE Products SET PhotoDirectory = testing WHERE [ProductCode]=" & "'" & [cmboNames] & "'"
    CurrentDB.Execute strSQL
    No code tags on phone access?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Same idea, you need to isolate the variable:
    Code:
    Dim strFolderPath As String
    strFolderPath = [cmboDirPath]
    "UPDATE Products SET PhotoDirectory = '" & strFolderPath & "' WHERE [ProductCode]='" & me.cmboNames & "'"
    
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Got it, works perfect. Thanks to both of you.

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

Similar Threads

  1. Problem updating unbound table records
    By swsailor in forum Access
    Replies: 8
    Last Post: 01-25-2019, 01:27 PM
  2. Replies: 2
    Last Post: 07-12-2016, 10:57 PM
  3. Two unbound boxes not updating in table
    By DeathByData in forum Access
    Replies: 29
    Last Post: 05-22-2013, 12:51 PM
  4. Unbound Object Frame Not Updating
    By MrSpadMan in forum Reports
    Replies: 7
    Last Post: 02-06-2013, 06:30 PM
  5. Replies: 4
    Last Post: 05-30-2011, 08:20 PM

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