Rani,
Looks like you're maybe working too hard at it - Access is ready to do more
than you think.
In the NotInList event, you call the AddCustFrm - which is fine (although
the syntax as posted looks wrong) - but the value that has been rejected is
not passed to the newly-opened form, so the user would have to enter it
again, which might annoy them. You might consider passing the NotInList
NewData value via OpenArgs into the AddCustFrm.
When in the AddCustFrm, it should not be necessary to at all concern
yourself about the 'calling' form Choze_Frm. Let that form look after
itself, when you close the AddCustFrm.
That can be organised simply by setting the Response arg of the NotInList -
as you try to do but have set it to the wrong option.
With regard to your issues:
1. Surely, the data from CustNameCombo is not intended for the cust_tbl? Is
it not _based_ on cust_tbl and intended to identify which Customer is
related to which Contract? Although you have not said so, I would expect the
CustNameCombo control to be based on the cust_tbl primary key, possibly
supported by a 2nd column of cust code or customer name or similar. Now if
"isn't being saved to the cust_Tbl " was a typo and you mean that the
Customer Id is not being saved to the contract table, then there are several
possible reasons why that might be so - one is that the cbx is _not_ based
on the primary key, another is that the cbx is not bound to the cust_id
field in the contracts table and that no other code is putting the chosen
cust_id in place, and maybe others. Unless the Customer name is the primary
key (g.forbid) then your code line
Me.CustNameCombo = NewData
has got to be a bit of a concern, and might go to explain the underlying
problem.
2. Your second issue is explained by a couple of coding mistakes. First, the
called form is not (based on posted code) modal and so any file edits would
not have taken place before any requery. Second, the requery that might have
been invoked by the Response arg isn't, because it's set to the wrong
option.
Revised coding scheme is outlined below.
It remains for you to get happy about the way you have bound the combo-box
to the underlying contracts table. That problem is not addressed in anything
below.
CD
' Choze_Frm
Private Sub CustNameCombo_NotInList(NewData As String, Response As Integer)
' ensure that "AddCustFrm" is closed, else acDialog and OpenArgs won't
bite
On local error resume next
Docmd.close acform,"AddCustFrm"
DoCmd.OpenForm "AddCustFrm", , , , ,acDialog,NewData
Response = acDataErrAdded
End Sub
'AddCustFrm
Private Sub Form_Open(Cancel as integer)
' Bring in any start-up value for Customer name (from CustNameCombo)
If "" <> Nz(Me.OpenArgs,"") Then
Me.CustName.DefaultValue = "=""" & Me.OpenArgs & """"
End If
End Sub
Private Sub SE_Btn_Click()
Me.Dirty = False ' force a save of the current record
' all the other stuff to do with Choze_Frm ... forget it
End Sub
Rani said:
Ok here is the issue
I have a contract (Choze_Frm) on wich I have a combo box (CustNameCombo)
A not in list event does the following:
Private Sub CustNameCombo_NotInList(NewData As String, Response As Integer)
Me.CustNameCombo = NewData
DoCmd.Minimize
DoCmd.OpenForm "AddCustFrm", acNormal, acDialog
Response = acDataErrContinue
End Sub
At the AddCustFrm (based on a table called Cust_TBL) I have a save button
that do the following:
Private Sub SE_Btn_Click()
On Error GoTo Err_SE_Btn_Click
Dim ctl As Control
Set ctl = Forms!Choze_Frm!CustNameCombo
DoCmd.Save
DoCmd.Minimize
' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.OpenForm "Choze_Frm"
DoCmd.GoToControl ctl.Name
DoCmd.Requery
Forms![Choze_Frm]![CustNameCombo] = ""
Forms![Choze_Frm]![CustNameCombo] =
Forms![AddCustFrm]![Shem_Cust]
Exit_SE_Btn_Click:
Exit Sub
Err_SE_Btn_Click:
MsgBox Err.Description
Resume Exit_SE_Btn_Click
End Sub
Here are the issues:
1.. The data from CustnameCombo isn't being saved to the cust_Tbl
all
the
rest of the information is being saved.
2.. after updating the fields in the cust_tbl and closing the AddCustFrm
the Customer name is being transferred to the CustnameCombo field on the
choze_frm but the combo isn't being requery
Any Ideas ?
Hi Rani,
The 'add to master list' form that you open ... is that modal?
If not, then your DoCmd.Requery may not bite.
For example, if you have
Private Sub xxx_NotInList
DoCmd.OpenForm zzzz
Me.xxx.Requery
etc
then the Requery of the combobox takes place before the new data has been
added.
You could perform the requery in the AfterUpdate event of the 'zzzz' form,
but you may decide that's to complicated - with all the argument-passing
involved.
Simplest (for now) route is to make the call to 'zzzz' be modal. So,
DoCmd.OpenForm zzzz,,,,, acDialog
Me.xxx.Requery
will do the job.
The downside is a slight cramping of style in the user interface.
CD
Sorry guys for posting again
my question is:
I have a combobox - while not on list event opens another form and
updates
information into the related table, closes the data entry form and goes
back
to the combobox form,
the information isn't appearing in the combobox.
I tried to run DoCmd.Requery but got no result out of it.
any idea ?