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!