
Originally Posted by
dluga20
Did you try the code I posted? It should not create tables from the form. It will only add records (rows) to existing tables...
It gives an error because the drop down is pulling the "ID" as the value and not the "text" that correlates with the table name.
With "Heads" selected in the drop down it will return a "1" instead of "Heads", this code sets the table to "tbl1" instead of "tblHeads". I really cant imagine that setting up an if statement here would be the most efficient solution for this, but that could be done as well, no?
Set rs = db.OpenRecordset("tbl" & <Name Of Your ComboBox>.Value)
Did I miss something setting up that table or will a drop down always return the ID as .value?
Edit: After looking into .value and how it works, I had the wrong idea about how these fields/controls worked. I also just realized there is a different between both controls and fields
.
It is a very simple table with 2 fields:
ID Type Name
1 Heads
2 Liners
3 Rods
4 Bonnets
5 Pumps
etc etc
ok, that was easy... ".text" solved that... but have to research "setting focus"
Ok, so it works! Amazing
Code:
Private Sub btnSubmittoDB_Click()
Set db = CurrentDb
Me.drdType.SetFocus
Set rs = db.OpenRecordset("tbl" & drdType.Text)
For i = 1 To Me.txtQuantity.Value
rs.AddNew
rs.Update
Next
MsgBox ("You are submitting " & txtQuantity & " to Pending Inspections for the " & drdType.Text & " Queue.")
End Sub