Results 1 to 11 of 11
  1. #1
    beerdini is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    3

    Combobox values to table

    I haven't used Access in almost 20 years but am trying to use the tools available to me for trying to build a database to help me search the details of a web filter that my company uses because the vendor doesn't have a good system to make searchable reports based on entering a client and finding all of the rules associated with it. This is a system that has been in place 10+ years, many hands in it over the years and many duplicate rules, etc... that need to be cleaned up. I'm able to export from the web filter and import into Access tables, now I'm trying to make the join tables so I can associate items, but after reading a bunch of posts and videos I can't figure out how to get things to write to the joining table. My tables are as follows:

    tblIP
    -ID (PK)
    -FirstIP
    -LastIP

    tblClientRule
    -tblIPID
    -tblPolicyID


    - 2 other ID's for tables not yet associated and null values are acceptable

    tblPolicies
    -ID (PK)
    -policyName

    I have created a form with:
    3 column combo box based on tblIP. ID is hidden, FirstIP shown, LastIP hidden but displayed in a text box next to combo
    2 column combo box based on tblPolicies. ID is hidden, policyName is shown

    I want to select the IP address/range in the first combo box, the policy in the 2nd combo box, and click a submit button to write the hidden ID values to their associated value in tblClientRule. I've tried several different versions of _Click on the box but so far nothing gets written to the table. I've tried several different variations but the latest I tried the following:

    Private Sub cmdSubmit_Click()
    Dim SQL as string
    SQL = "INSERT INTO tblClientRule (tblIPID,tblPolicyID) &_
    VALUES (Me![cboIP]Column(0),Me![cboPolicy]Column(0));"

    Again, the intent is to have the ID's from tblIP and tblPolicies to be written to the associated field in tblClientRule. This will allow me to do future reporting where I can query an IP address and see all of the policies that have been assigned to that IP, or search the opposite. Right now I click the button, nothing changes, no record update at the bottom of my form and nothing else added to the table.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    Put your sql string into a string variable and debug.print that to see what you have not what you think you have.
    You are at least missing a . before Column
    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

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Can you provide a few examples (can be dummy/mock up data) for each of your tables to provide some context?

    Your SQL is not being executed if your Private Sub cmdSubmit_Click() is complete as shown. The procedure also has syntax issues.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Code:
    SQL = "INSERT INTO tblClientRule (tblIPID, tblPolicyID) " & _
             "VALUES (" & Me.cboIP.Column(0) & ", " & Me.cboPolicy.Column(0));"
    Show code that actually executes the SQL statement.

    But why use VBA and not simply bind form and controls?

    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
    Cottonshirt is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Feb 2018
    Posts
    116
    SQL is a reserved word.


    good luck with your project.


    Cottonshirt

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Yes, SQL is reserved word for JET, ODBC, ANSI-92 but VBA has no problem with it declared as a variable. However, could play it safe and use strSQL instead.
    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.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  8. #8
    beerdini is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    3
    Quote Originally Posted by orange View Post
    Awaiting some response from beerdini.
    Here are some images of sample data, relationship structure, code and the input box that I'm making. I apologize about image quality, it triggers exfiltration alarms if I try to send to myself so had to do the pic route.

    https://u.pcloud.link/publink/show?c...BTz8BsYp1J6DYk

    I added the Debug.print command that someone suggested and I'm not seeing any difference when I click the submit button.

    Since I haven't really developed in Access in a long time my relationship structure might not be usable. In the system I'm trying to map and report I have 2 types of users, IP and actual user, and 2 types of rules, policies and exceptions. An IP or User can have multiple policies or rules assigned to them which is why I'm trying to go for the format that I'm using for tblClientRule. I'm trying to be ambitious and use a single table rather IP/Policy, IP/Exception, User/Policy, User/Exception, since ultimately I am planning to build this out to which URLs are managed by each policy and exception. Again each URL can be used in multiple policies or exceptions.

    So what I'm trying to do right now is write the values of the ID fields in the IP and Policy tables to the 1st and 3rd columns in the sample data that I provided, the others can remain null, if that is permissible by access rules. Being able to do this is really the foundation of me being able to associate the IPs, Users, Policies, Exceptions and URLs with each other and once I have this down I'll be busy with linking the data.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 8 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Did you see post #4?
    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.

  11. #11
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    Your INSERT statement is missing the following line after the Debug.Print strSQL line :-

    CurrentDb.Execute strSQL, dbFailOnError
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

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

Similar Threads

  1. Replies: 2
    Last Post: 04-09-2016, 01:23 PM
  2. Replies: 3
    Last Post: 03-02-2016, 06:05 PM
  3. Replies: 14
    Last Post: 07-25-2013, 11:17 PM
  4. Combobox setting other combobox values problem
    By maxmaggot in forum Programming
    Replies: 8
    Last Post: 06-30-2013, 07:18 AM
  5. Replies: 2
    Last Post: 02-13-2013, 09:45 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