kimarimonku
New member
- Local time
- Today, 13:50
- Joined
- Jun 15, 2015
- Messages
- 3
I have a basic form linked with a subform inside of it. The main form has a list of customers in a combobox and the subform lists all the things they have ordered from us. This all works perfectly fine, I can add data to the list of things ordered and it's ok.
I decided instead of using a whole extra form to add customers I'd just have a not in list event and allow users to add customers through there, bit more intuitive and cut down on forms. This is my first time using VBA so I decided to get help and found this link from Microsoft Dev that seems to be exactly what I need using the second example: (can't link URLs)
It works to certain extent except one small problem, if I add a customer I have to close and reopen the form to be able to add/remove data from them in the subform. If I leave the form open and try to enter in data in the subform immediately it just shows whatever customer I had last on the combobox and adds it to the last customer as well.
It works perfectly fine if I reopen it so I thought it was some kind of query or update snafu but all the VBA code examples I found don't seem to do anything. Not exactly sure where to go from here.
Code of the example I found that mostly worked except the update problem
I decided instead of using a whole extra form to add customers I'd just have a not in list event and allow users to add customers through there, bit more intuitive and cut down on forms. This is my first time using VBA so I decided to get help and found this link from Microsoft Dev that seems to be exactly what I need using the second example: (can't link URLs)
It works to certain extent except one small problem, if I add a customer I have to close and reopen the form to be able to add/remove data from them in the subform. If I leave the form open and try to enter in data in the subform immediately it just shows whatever customer I had last on the combobox and adds it to the last customer as well.
It works perfectly fine if I reopen it so I thought it was some kind of query or update snafu but all the VBA code examples I found don't seem to do anything. Not exactly sure where to go from here.
Code of the example I found that mostly worked except the update problem
PHP:
Private Sub cboDept_NotInList(NewData As String, Response As Integer)
Dim oRS As DAO.Recordset, i As Integer, sMsg As String
Dim oRSClone As DAO.Recordset
Response = acDataErrContinue
If MsgBox("Add dept?", vbYesNo) = vbYes Then
Set oRS = CurrentDb.OpenRecordset("tblDepartments", dbOpenDynaset)
oRS.AddNew
oRS.Fields(1) = NewData
For i = 2 To oRS.Fields.Count - 1
sMsg = "What do you want for " & oRS(i).Name
oRS(i).Value = InputBox(sMsg, , oRS(i).DefaultValue)
Next i
oRS.Update
cboDept = Null
cboDept.Requery
DoCmd.OpenTable "tblDepartments", acViewNormal, acReadOnly
DoCmd.GoToRecord acDataTable, "tblDepartments", acLast
End If
End Sub