I have 5 fields on a form used for inputing a new record. 3 of them are autofilled with data from a different table than what the form is linked to...and the other 2 are user filled. Only 4 of the fields get INSERT(ed) INTO the table that the form is linked to. At first, the 2 fields the user entered into were bound to the table, but I couldn't get all 4 fields to save into a single record. So I had to make them all unbound and use SQL to save the record in order to for it to work right. I used the last field's AfterUpdate event to run the SQL, but now I can't get it to trigger the next new record...if I am not making any sense, please let me know..
here is my code...
Public Month_Name As String
Public Sequence As Integer
Public Openlbs As Double
Public Closelbs As Double
Private Sub Item_NotInList(NewData As String, Response As Integer)
Response = fNotInList(NewData, "tblItem", "Item")
End Sub
Private Sub Form_Load()
Call dbInitialize 'the recordset is created in a module
rstEOM_Count.MoveFirst
txtSequence.SetFocus 'txtsequence is a field populated by the recordset
txtSequence.Text = rstEOM_Count!Sequence 'populating the first new record with data from the recordset
Sequence = txtSequence.Text
txtDesc.SetFocus 'txtDesc is a field populated by the recordset
txtDesc.Text = "'" & rstEOM_Count!ItemDescription & "'"
cboMonthName.SetFocus
cboMonthName.Text = MonthName(DatePart("m", Date) - 1) 'setting a default value for the combobox
Month_Name = cboMonthName.Text
txtOpeninglbs.SetFocus 'txtopeninglbs is the first field the user enters
End Sub
Private Sub txtClosinglbs_AfterUpdate() 'this is the last field on the form
Dim Sql As String
Closelbs = txtClosinglbs.Text 'txtClosinglbs is the other field the user enters
Sql = "INSERT INTO tblMonthly_Item_Total ([EOM_Month_Name], [SequenceID], [Openinglbs], [Closinglbs])" & _
" VALUES ('" & Month_Name & "', " & Sequence & ", " & Openlbs & ", " & Closelbs & ");"
DoCmd.RunSQL Sql 'saving the record to the table
With rstEOM_Count 'populate the next new record with data from the recordset
If Not .EOF Then
.MoveNext
txtSequence.SetFocus
txtSequence.Value = !Sequence
Sequence = txtSequence.Text
txtDesc.SetFocus
txtDesc.Value = "'" & !ItemDescription & "'"
txtOpeninglbs.SetFocus
Else
.MoveFirst
End If
End With
End Sub
Private Sub txtOpeninglbs_AfterUpdate()
Openlbs = txtOpeninglbs.Text
End Sub
Hope this makes sense...I'm really lost on this..
here is my code...
Public Month_Name As String
Public Sequence As Integer
Public Openlbs As Double
Public Closelbs As Double
Private Sub Item_NotInList(NewData As String, Response As Integer)
Response = fNotInList(NewData, "tblItem", "Item")
End Sub
Private Sub Form_Load()
Call dbInitialize 'the recordset is created in a module
rstEOM_Count.MoveFirst
txtSequence.SetFocus 'txtsequence is a field populated by the recordset
txtSequence.Text = rstEOM_Count!Sequence 'populating the first new record with data from the recordset
Sequence = txtSequence.Text
txtDesc.SetFocus 'txtDesc is a field populated by the recordset
txtDesc.Text = "'" & rstEOM_Count!ItemDescription & "'"
cboMonthName.SetFocus
cboMonthName.Text = MonthName(DatePart("m", Date) - 1) 'setting a default value for the combobox
Month_Name = cboMonthName.Text
txtOpeninglbs.SetFocus 'txtopeninglbs is the first field the user enters
End Sub
Private Sub txtClosinglbs_AfterUpdate() 'this is the last field on the form
Dim Sql As String
Closelbs = txtClosinglbs.Text 'txtClosinglbs is the other field the user enters
Sql = "INSERT INTO tblMonthly_Item_Total ([EOM_Month_Name], [SequenceID], [Openinglbs], [Closinglbs])" & _
" VALUES ('" & Month_Name & "', " & Sequence & ", " & Openlbs & ", " & Closelbs & ");"
DoCmd.RunSQL Sql 'saving the record to the table
With rstEOM_Count 'populate the next new record with data from the recordset
If Not .EOF Then
.MoveNext
txtSequence.SetFocus
txtSequence.Value = !Sequence
Sequence = txtSequence.Text
txtDesc.SetFocus
txtDesc.Value = "'" & !ItemDescription & "'"
txtOpeninglbs.SetFocus
Else
.MoveFirst
End If
End With
End Sub
Private Sub txtOpeninglbs_AfterUpdate()
Openlbs = txtOpeninglbs.Text
End Sub
Hope this makes sense...I'm really lost on this..