Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Posts
    47

    Unanswered: Adding Data to Table Using Unbound Form

    I have a small problem chich I am trying to fix.
    I would like to add a new row to my database using an unbound form. The unbound form has 2 textboxes and 2 comboboxes(the sources are 2 separate tables related to the main table). I managed to build the SQL query in order to add the information but the problem is that every time the user hits the Save button a generic MS Access message comes up whether the user is sure he wants to add a new row to the specified table. Is is possible to substitute it with my own. Also underneath is my code, can somebody tell me whether I wrote it right and if there is a better way to do it.

    Private Sub Command13_Click()

    Code:
    Dim strSQL As String
    
    strSQL = "INSERT INTO tblUsers (ID, Password, System, Staff) VALUES(txtUsername, txtPassword, cmbSystem, cmbStaff)"
    
    DoCmd.RunSQL strSQL
    
    End Sub
    Thank you

  2. #2
    Join Date
    Jul 2004
    Posts
    156
    Well, if you're sure you want to use SQL to add the records to the table instead of ADO, just go to Tools-->Options, click on the Edit/Find tab, and under Confirm, uncheck Action queries. I have Access 2002 so that's the only layout I can confirm. The options windows may be different in other versions. Since an Append query is an action query, this should take care of your problem. I hope. :-)
    DocX

    The teachings of God's Begotten: 2 John 1:9

  3. #3
    Join Date
    Sep 2004
    Posts
    47

    Thank You

    Thank you DocX. It worked.
    I am using SQL since I thought that it is the easiest and in fact...the only way. I am unfortunately not that proficient in Access so I do not know most of the functions. What does ADO involve? If you do not want to explain can you please point me into a good direction where I can read about it. Thank you

    a.

  4. #4
    Join Date
    Apr 2004
    Posts
    41
    DoCmd.SetWarnings False (True to turn back on) Don't forget to turn back on. You can use If and Messagebox to set up your own warning/confirmation.

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Another option, which does the same thing, but in code is:

    SetOption "Confirm Action Queries",False

    Then after you run your query you can turn the warnings back on:

    SetOption "Confirm Action Queries", True

  6. #6
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    you can use docmd.setwarnings method to supress action query messages.
    Code:
    Dim strSQL As String strSQL = "INSERT INTO tblUsers (ID, Password, System, Staff) VALUES(txtUsername, txtPassword, cmbSystem, cmbStaff)"
    Docmd.Setwarnings false
    DoCmd.RunSQL strSQL
    Docmd.Setwarnings true
    End Sub
    ghozy.

  7. #7
    Join Date
    Sep 2004
    Posts
    47

    Thanks

    Wow...6 views and 5 replies already. Nnow I feel kinda stupid for asking :-)
    Thank you everybody.

  8. #8
    Join Date
    Jul 2004
    Posts
    156
    I guess I should've mentioned that this option will, indeed, turn off ALL prompts to ANY action queries.

    Following the above coded options would be a safer bet if you just wanted to turn off the prompts for this addition alone. However, if you never want any action queries to prompt you, go for unchecking the confirm checkbox. That's my opinion and it only matters as much as you want it to.

    As for recordset handling with ADO and ADOX, my reference is Access 2002 Developer's Handbook, which gives the basics. There's a plethora of resources out there including on the Internet, from basic to in-depth explanations. Anyone have any suggestions for web-based tutorials?
    DocX

    The teachings of God's Begotten: 2 John 1:9

  9. #9
    Join Date
    Jul 2004
    Posts
    156
    Don't feel stupid. The number of posts I have? Well, that's 90-95% questions and NOT answers. If you don't know, you HAVE to learn it from SOMEWHERE.
    DocX

    The teachings of God's Begotten: 2 John 1:9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •