B
Billp
Hi,
Can I do what I am hoping I can do with running a routine from a module on
the after update of a combo box.
What I am trying to do is catch if a new entry is there, and then not allow
the form to be saved (latter issue), and if the entry is part of the existing
database continue to populate data form that table to the forms controls.
The afterupdate is as follows
Call SER_Update ' from module
Me.Refresh
Then to the module
Sub SER_Update()
'user has entered a customer from the combo
'check if it is already in the customer database
'if it isn't then stop the enquiry form being saved
'by setting a flag
'until the new customer is added to the db and everything is updated
Dim rst As DAO.Recordset 'rsttblCustomers
Dim strsql As String
Dim strNewCust As String
Dim User_form As Access.Form 'users form
strNewCust = User_form!frmSER!cboCompany_Name
Set rst = CurrentDb().OpenRecordset("tblCustomers", dbOpenDynaset)
strsql = strNewCust
rst.FindFirst strsql
If rst.NoMatch Then 'the input is not in the list
' do something like set the save form to no until customer is added
User_form!frmSER!FormSaved = True 'sets the flag
'set up a messgage to notofy user that form cannot be saved
Else 'there is a match and customer is already in database
'populate fields with existinmg data
'by selecting the row you have effectually said start
Dim strFilter As String
' Evaluate filter before it is passed to Dlookup function.
strFilter = "[Customer_Record_ID] = " &
User_form!frmSER![cboCompany_Name].Column(1) 'as it is a numeric value
'Update form controls based on value selected in cboCompanyName combo box
User_form!frmSER![Customer_Phone] = Nz(DLookup("[Customer_Phone]",
"tblCustomers", strFilter))
User_form!frmSER![IndustryCode] = Nz(DLookup("[CustomerSIC]",
"tblCustomers", strFilter))
'User_form!frmSER![Company_Name] = Nz(DLookup("[Company_Name]",
"tblCustomers", strFilter))
User_form!frmSER![CustomerID] = Nz(DLookup("[CustomerID]",
"tblCustomers", strFilter))
User_form!frmSER![Address] = Nz(DLookup("[Address]", "tblCustomers",
strFilter))
User_form!frmSER![Address1] = Nz(DLookup("[Address1]", "tblCustomers",
strFilter))
User_form!frmSER![Address2] = Nz(DLookup("[Address2]", "tblCustomers",
strFilter))
User_form!frmSER![Address3] = Nz(DLookup("[Address3]", "tblCustomers",
strFilter))
User_form!frmSER![Address4] = Nz(DLookup("[Address4]", "tblCustomers",
strFilter))
User_form!frmSER![Address5] = Nz(DLookup("[Address5]", "tblCustomers",
strFilter))
User_form!frmSER![Address6] = Nz(DLookup("[Address6]", "tblCustomers",
strFilter))
End If
'return to form
End Sub
What I am getting is an error 91 with a variable not set????????? on the
cboafterupdate.
Help please - any help appreciated
Thanks
Bill
Can I do what I am hoping I can do with running a routine from a module on
the after update of a combo box.
What I am trying to do is catch if a new entry is there, and then not allow
the form to be saved (latter issue), and if the entry is part of the existing
database continue to populate data form that table to the forms controls.
The afterupdate is as follows
Call SER_Update ' from module
Me.Refresh
Then to the module
Sub SER_Update()
'user has entered a customer from the combo
'check if it is already in the customer database
'if it isn't then stop the enquiry form being saved
'by setting a flag
'until the new customer is added to the db and everything is updated
Dim rst As DAO.Recordset 'rsttblCustomers
Dim strsql As String
Dim strNewCust As String
Dim User_form As Access.Form 'users form
strNewCust = User_form!frmSER!cboCompany_Name
Set rst = CurrentDb().OpenRecordset("tblCustomers", dbOpenDynaset)
strsql = strNewCust
rst.FindFirst strsql
If rst.NoMatch Then 'the input is not in the list
' do something like set the save form to no until customer is added
User_form!frmSER!FormSaved = True 'sets the flag
'set up a messgage to notofy user that form cannot be saved
Else 'there is a match and customer is already in database
'populate fields with existinmg data
'by selecting the row you have effectually said start
Dim strFilter As String
' Evaluate filter before it is passed to Dlookup function.
strFilter = "[Customer_Record_ID] = " &
User_form!frmSER![cboCompany_Name].Column(1) 'as it is a numeric value
'Update form controls based on value selected in cboCompanyName combo box
User_form!frmSER![Customer_Phone] = Nz(DLookup("[Customer_Phone]",
"tblCustomers", strFilter))
User_form!frmSER![IndustryCode] = Nz(DLookup("[CustomerSIC]",
"tblCustomers", strFilter))
'User_form!frmSER![Company_Name] = Nz(DLookup("[Company_Name]",
"tblCustomers", strFilter))
User_form!frmSER![CustomerID] = Nz(DLookup("[CustomerID]",
"tblCustomers", strFilter))
User_form!frmSER![Address] = Nz(DLookup("[Address]", "tblCustomers",
strFilter))
User_form!frmSER![Address1] = Nz(DLookup("[Address1]", "tblCustomers",
strFilter))
User_form!frmSER![Address2] = Nz(DLookup("[Address2]", "tblCustomers",
strFilter))
User_form!frmSER![Address3] = Nz(DLookup("[Address3]", "tblCustomers",
strFilter))
User_form!frmSER![Address4] = Nz(DLookup("[Address4]", "tblCustomers",
strFilter))
User_form!frmSER![Address5] = Nz(DLookup("[Address5]", "tblCustomers",
strFilter))
User_form!frmSER![Address6] = Nz(DLookup("[Address6]", "tblCustomers",
strFilter))
End If
'return to form
End Sub
What I am getting is an error 91 with a variable not set????????? on the
cboafterupdate.
Help please - any help appreciated
Thanks
Bill