Results 1 to 7 of 7
  1. #1
    dapoole is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2010
    Posts
    11

    Execute Insert Statement When Checkbox Is Ticked?

    Hi there,



    I'm trying to get an Insert statement to execute whenever the user ticks the tickbox however my code is failing to find the output table 'Manager':

    Code:
    Private Sub Check34_AfterUpdate()
     Dim db As DAO.Database
       Dim qdf As DAO.QueryDef
       Dim varItem As Variant
       Dim strCriteria As String
       Dim strSql As String
       Set db = CurrentDb()
        
    If (Me!Check34) = -1 Then
    
    
    DoCmd.RunSQL "INSERT INTO Manager (manID) " _
     & "VALUES(" _
     & "'" & Me!empID & "') "
       
      End If
      
    End Sub
    Please can you advise?

    TIA

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Change it to make it easier to read. I put an space between "VALUE" and "(". Anyway, try the code below to see if you still getting errors. Post exact error message if you can.

    One more thing, does the table "Manager" exist with column "manID"?

    Private Sub Check34_AfterUpdate()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim varItem As Variant
    Dim strCriteria As String
    Dim strSql As String

    Set db = CurrentDb()
    If Check34 = -1 Then
    strSql = "INSERT INTO Manager (manID) "
    strSql = strSql & "VALUES ("
    strSql = strSql & "'" & empID & "')"
    DoCmd.RunSQL strSql
    End If
    End Sub

  3. #3
    dapoole is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2010
    Posts
    11
    Thanks but it still fails after tidying up the code. Exact error message is "Run-time error '3192': Could not find output table 'Manager'."

    The manager table is a linked table and does exist with a unique key manID which links to Employee empID.

  4. #4
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    I have tested the code and it works.

    Is the linked table "Manager" in SQL SERVER, or another Access database, or Excel, ......?

    Can you also verify what column "manID" data type (is it TEXT, NUMBER, .....)?

  5. #5
    dapoole is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2010
    Posts
    11
    It's SQL Server:

    Code:
    CREATE TABLE test.dbo.Manager(
    manID INT,
    manForename VARCHAR(50),
    manSurname VARCHAR(50))
    I can connect to the table and view it's contents so the tables exists. The problem must be in the VB code somewhere?

  6. #6
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Ok, do you have table "Manager" listed? or is it "dbo_Manager" or something?

  7. #7
    dapoole is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Oct 2010
    Posts
    11
    That's it thanks. I had the insert statement written as INSERT INTO Manager when it should read dbo_Manager. Many thanks.

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

Similar Threads

  1. Replies: 7
    Last Post: 01-22-2014, 01:09 PM
  2. Running code in function if checkbox is ticked
    By lewis1682 in forum Programming
    Replies: 7
    Last Post: 09-22-2013, 05:35 PM
  3. Replies: 4
    Last Post: 06-24-2013, 03:36 AM
  4. If Checkbox is ticked, Data Must be entered
    By DTK0902 in forum Access
    Replies: 8
    Last Post: 12-01-2012, 04:32 PM
  5. Open report if checkbox is ticked
    By Patience in forum Reports
    Replies: 3
    Last Post: 06-23-2010, 08:34 AM

Tags for this Thread

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