Hi,
I have a combo-box in A form where the values r taken from a query (select query from a table).
When a value entered is not from list, a "notonlist" event goes to a procedure (following) in which, asks the user if wants to add the item to the list. If yes, then goes to B form, automatically puts there the not-in-list value entered in A form, and then the user manually fills in other details in record. Then the user presses a button that takes closes the form+save, and goes back to A form, where now the combo-box list is updated(!), and when u click the value in the comco-box that was entered before, it opens the combo list and then u can see that it is in the right place in the list.
So far so good.
But - other details (some fields) in A form record, should be taken from the brand new record in B table. Fiedls that matches the value that was entered to the combo-box.
But that is not done, unless I just select the item again from the combo-list.
The error I get is that the value (in comco) is not found in B table. When I open B table, it is there.
I do not understand: If the form is updated, and the combo-box has already taken the new value from it, and also entered it to the list in combo in FORM A, then it means that A form can see B form recent details.
Why can't it see the same record from table?
How can I refresh it, without loosing the new record (the new value actually)?
I hope I am clear.
The code:
'*********
Private Sub BudgetNo_NotInList(NewBudgNo As String, Response As Integer)
'Refreshes the list in the budget no combo-box. Needed in case
'there has been just added a new item to the budgets form
Me!BudgetNo.RowSourceType = "Table/Query"
Me!BudgetNo.RowSource = "SELECT [budgets].[budgetno], [budgets].[ownername] FROM budgets ORDER BY [budgets].[budgetno];"
Me!BudgetNo.Value = NewBudgNo
If Me!BudgetN
nNotInList = False Then 'I.e. - if it IS part of the list now
Exit Sub
Else
MsgBox ("requrey shows not in list still"
GoTo step2
End If
step2:
Dim Msg, Style, Title, MyString
Msg = "The item is not on the List. Do u want to add it?" ' This is the message on the dialog box.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Gives you Yes and No buttons.
Title = "Not in list item" ' Message Box Title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' If User wants to add a new item, then
DoCmd.OpenForm ("frmbudgets"
'open the right form,
DoCmd.GoToRecord , , acNewRec 'go to new rec
'DoCmd.GoToControl (budgetNo)
Forms!frmbudgets!BudgetNo.Value = NewBudgNo 'and set the value of budgetNo as was entered to the current form
Else ' If No.
MsgBox ("No"
End If
End Sub
'**************
Thanks
I have a combo-box in A form where the values r taken from a query (select query from a table).
When a value entered is not from list, a "notonlist" event goes to a procedure (following) in which, asks the user if wants to add the item to the list. If yes, then goes to B form, automatically puts there the not-in-list value entered in A form, and then the user manually fills in other details in record. Then the user presses a button that takes closes the form+save, and goes back to A form, where now the combo-box list is updated(!), and when u click the value in the comco-box that was entered before, it opens the combo list and then u can see that it is in the right place in the list.
So far so good.
But - other details (some fields) in A form record, should be taken from the brand new record in B table. Fiedls that matches the value that was entered to the combo-box.
But that is not done, unless I just select the item again from the combo-list.
The error I get is that the value (in comco) is not found in B table. When I open B table, it is there.
I do not understand: If the form is updated, and the combo-box has already taken the new value from it, and also entered it to the list in combo in FORM A, then it means that A form can see B form recent details.
Why can't it see the same record from table?
How can I refresh it, without loosing the new record (the new value actually)?
I hope I am clear.
The code:
'*********
Private Sub BudgetNo_NotInList(NewBudgNo As String, Response As Integer)
'Refreshes the list in the budget no combo-box. Needed in case
'there has been just added a new item to the budgets form
Me!BudgetNo.RowSourceType = "Table/Query"
Me!BudgetNo.RowSource = "SELECT [budgets].[budgetno], [budgets].[ownername] FROM budgets ORDER BY [budgets].[budgetno];"
Me!BudgetNo.Value = NewBudgNo
If Me!BudgetN
Exit Sub
Else
MsgBox ("requrey shows not in list still"
GoTo step2
End If
step2:
Dim Msg, Style, Title, MyString
Msg = "The item is not on the List. Do u want to add it?" ' This is the message on the dialog box.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Gives you Yes and No buttons.
Title = "Not in list item" ' Message Box Title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' If User wants to add a new item, then
DoCmd.OpenForm ("frmbudgets"
DoCmd.GoToRecord , , acNewRec 'go to new rec
'DoCmd.GoToControl (budgetNo)
Forms!frmbudgets!BudgetNo.Value = NewBudgNo 'and set the value of budgetNo as was entered to the current form
Else ' If No.
MsgBox ("No"
End If
End Sub
'**************
Thanks