Jhart22889
Registered User.
- Local time
- Today, 14:24
- Joined
- Feb 22, 2013
- Messages
- 13
Hello all I have a dilemma with some code that creates table entries from multiple subforms. There are three subforms that are based on one table, two subforms are in single form view as they only require one entry per project however the third subform is in datasheet view and has the ability to create several rows associated to one project. In the code the row is created combining all of this information but I cannot figure out how to reset the cursor to start a new row for multiple entries in the third subform. In an example say the three subforms all pertain to purchasing costs. One has y/n questions of overall equipment costs that may be incurred per project, the other has an estimate of overall shipment costs for the project and the third table is the datasheet in which you pick your purchase items and cost of that item. Is it possible to use VBA to call a new row and reset the cursor to that new row for data entry? ANY help is definitely appreciated!:banghead:
I use this and a similar code for the two single forms and this code for the datasheet form:
Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'Sets the database as well as the file path
cn.Open "Provider = Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= C:\Users\Pretend\Documents\Estimate\Access\hypothetical.accdb;"
'This gets the public variable FFProjectNumber. FFProjectNumber is created when the Start Date is selected on the front form
GetPublicVariable = FFProjectNumber
'Opens the desired recordset
rs.Open "tblAdditionalProcurement", cn, adOpenDynamic, adLockOptimistic
'Filters the recordset for ProjectIDs that are like the FFProjectNumber
rs.Filter = "ProjectID Like " & FFProjectNumber
'Sets the fields in the rs equal to the values that the user input or that was calculated on the top of the procurement field
rs.Fields("FedEx") = Me.txtFedEx.Value
rs.Fields("FedExCost") = Me.txtFedExCost.Value
rs.Fields("FedExFee") = Me.txtFedExFee.Value
rs.Fields("PCard") = Me.txtPcard.Value
rs.Fields("PcardCost") = Me.txtPcardCost.Value
rs.Fields("PcardFee") = Me.txtPcardFee.Value
'Updates, saves and closes the recordset
rs.Update
rs.Save
rs.Close
I use this and a similar code for the two single forms and this code for the datasheet form:
Code:
'Dims and sets the connections and the recordsets as new
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'Sets the database as well as the file path
cn.Open "Provider = Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= C:\Users\Pretend\Documents\Estimate\Access\hypothetical.accdb;"
'MsgBox FFProjectNumber The variable was correct when it was passed to this messagebox
Dim strProcurementType As String
strProcurementType = cboProcurement
'Opens the desired recordset
rs.Open "tblProcurementFee", cn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
'MsgBox strProcurementType
Do While Not rs.EOF
If rs.Fields("ProcurementTransactionName") = strProcurementType Then
txtFeetotal = rs.Fields("Fee").Value
rs.MoveNext
'MsgBox "Part 1 of the loop"
Else
rs.MoveNext
'MsgBox "Part 2 of the loop"
End If
Loop
'MsgBox "You have successfully popped out of the do loop"
rs.Close
cn.Close
End Sub