Results 1 to 2 of 2
  1. #1
    VaNa is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    1

    Help! Code to insert data from form into table doesn't work

    Hello!



    I have a problem with a code that I tried to use in order to insert data written into a form into the respective tables. In my form, I inserted 3 comboboxes where you can choose products that you want to order. When clicking a command button, the data is supposed to be inserted into two different tables which perfectly works if all three boxes are enabled. The problem therefore is, that the code (see below) only works, if all three comboboxes are filled. However, I also want it to work if only one combobox has been enabled.

    Private Sub Befehl90_Click()
    CurrentDb.Execute _
    "INSERT INTO tbl_Aufträge(reNr, reDatum, ku_ID, empf_ID, versa_ID, beza_ID) " _
    & "SELECT " & Me.Controls("txtreNr").Value & ", " _
    & "'" & Nz(Me.Controls("txtRechnungsdatum").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtKundenID").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtpersID").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtversaID").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtbezaID").Value, "") & "'", dbFailOnError


    If Befehl90.Enabled = True Then
    CurrentDb.Execute _
    "INSERT INTO tbl_Auftragspositionen(re_ID, art_ID, reposMenge) " _
    & "SELECT " & Me.Controls("txtreID").Value & ", " _
    & "'" & Nz(Me.Controls("txtartID1").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtMenge").Value, "") & "'", dbFailOnError


    End If




    If Befehl90.Enabled = True And cboArtikel2.Enabled Then
    CurrentDb.Execute _
    "INSERT INTO tbl_Auftragspositionen(re_ID, art_ID, reposMenge) " _
    & "SELECT " & Me.Controls("txtreID").Value & ", " _
    & "'" & Nz(Me.Controls("txtartID2").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtMenge2").Value, "") & "'", dbFailOnError


    End If



    If Befehl90.Enabled = True And cboArtikel3.Enabled Then
    CurrentDb.Execute _
    "INSERT INTO tbl_Auftragspositionen(re_ID, art_ID, reposMenge) " _
    & "SELECT " & Me.Controls("txtreID").Value & ", " _
    & "'" & Nz(Me.Controls("txtartID3").Value, "") & "', " _
    & "'" & Nz(Me.Controls("txtMenge3").Value, "") & "'", dbFailOnError

    End If


    End Sub




    I hope that someone can help me. Thank you!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why would you test if Befehl90 is enabled? If it's not enabled, can't click on it.

    See only 2 comboboxes referenced.

    Each If Then is independent and should run. Have you step debugged?

    Why use code to create records? Why not form/subform arrangement and user input direct to controls bound to fields?


    Please post code within CODE tags to retain indenting and readability.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-10-2017, 10:27 AM
  2. Replies: 1
    Last Post: 09-25-2016, 01:43 PM
  3. Replies: 9
    Last Post: 07-13-2015, 09:46 AM
  4. Replies: 8
    Last Post: 07-03-2015, 05:03 PM
  5. Replies: 2
    Last Post: 12-04-2012, 01:03 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