PDA

View Full Version : [SOLVED:] What is wrong with this this code? the second Sub is not giving me the desired output



G.Gard
02-02-2015, 11:50 AM
Hello, I've been stumped on this for a while now. I have changed the problem lines, I'm not sure on what the exact problem is so any help would be greatly appreciated!
If you need me to upload this for further assessment please ask.


Option Compare Database


Private Sub Customer_AfterUpdate()
Me.Company = Null
Me.Company.Requery
Me.Company = Me.Company.ItemData(0)
End Sub
Private Sub Form_Current()
Me.Company.Requery
End Sub
Private Sub Form_Load()
Me.Customer = Me.Customer.ItemData(0)
Call Customer_AfterUpdate
End Sub


Private Sub Customer_NotInList(NewData As String, Response As Integer)


Dim dbsCustomers As DAO.Database
Dim rstCustomers As DAO.Recordset
Dim intAnswer As Integer


On Error GoTo ErrorHandler


intAnswer = MsgBox("Add " & NewData & " to the list of customers?", _
vbQuestion + vbYesNo)


If intAnswer = vbYes Then


' Add Customer stored in NewData argument to the customers table.
Set dbsCustomers = CurrentDb
Set rstCustomers = dbsCustomers.OpenRecordset("Customers")
rstCustomers.AddNew
rstCustomers!ExplorationCoOrCustomerName = NewData
rstCustomers.Update


Response = acDataErrAdded ' Requery the combo box list.
Else
Response = acDataErrDisplay ' Require the user to select
' an existing customer.
End If


rstCustomers.Close
dbsCustomers.Close


Set rstCustomers = Nothing
Set dbsCustomers = Nothing
Response = 0
NewData = ""



Exit Sub

ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub


Private Sub Company_NotInList(NewData As String, NewDataID As Long, Response As Integer)

Dim dbsCustomerss As DAO.Database
Dim rstCompany As DAO.Recordset
Dim intAnswer As Integer

On Error GoTo ErrorHandler

intAnswer = MsgBox("Add " & NewData & " to the list of Company?", _
vbQuestion + vbYesNo)

If intAnswer = vbYes Then

Add New Company stored in NewData argument to the Company table.
Add CustomerID stored in NewDataID to Company Table
Set dbsCustomerss = CurrentDb
Set rstCompany = dbsCustomerss.OpenRecordset("Company")
rstCompany.AddNew
rstCompany!CompanyName = NewData
rstCompany!CustomerID = NewDataID
rstCompany.Update

Response = acDataErrAdded ' Requery the combo box list.
Else
Response = acDataErrDisplay ' Require the user to select
' an existing shipper.
End If

rstCompany.Close
dbsCustomerss.Close

Set rstCompany = Nothing
Set dbsCustomerss = Nothing

Exit Sub


ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub


Private Sub Company_NotInList(NewData As String, Response As Integer)

Dim dbsCompany As DAO.Database
Dim rstCompany As DAO.Recordset
Dim intAnswer As Integer

On Error GoTo ErrorHandler

intAnswer = MsgBox("Add " & NewData & " to the list of Company?", _
vbQuestion + vbYesNo)

If intAnswer = vbYes Then

' Add Company stored in NewData argument to the Company table.
Set dbsCompany = CurrentDb
Set rstCompany = dbsCompany.OpenRecordset("Company")
rstCompany.AddNew
rstCompany!CompanyName = NewData
rstCompany.Update

Response = acDataErrAdded ' Requery the combo box list.
Else
Response = acDataErrDisplay ' Require the user to select
' an existing Company.
End If

rstCompany.Close
dbsCompany.Close

Set rstCompany = Nothing
Set dbsCompany = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub







Please and Thank You!