C
Chris
I am having trouble saving data in a record.
Using NotInList event for a client selector combo box I add a new record for
a client and open a data entry form to enter data for a new (previously
non-existent client).
Using the code below I add the record to my client table, but no data (other
than that key field) stays in the table.
Code attached to NotInList event:
Dim dbsMyDatabase As DAO.Database
Dim rstClients As DAO.Recordset
Dim intAnswer As Integer
Dim stdocName, stLinkCriteria As String
stdocName = "1frmDEClient"
stLinkCriteria = "[ClientID]=" & "'" & NewData & "'"
NewData = UCase(NewData)
On Error GoTo ErrorHandler
intAnswer = MsgBox("Add " & NewData & " to the list of Clients?", _
vbQuestion + vbYesNo)
If intAnswer = vbYes Then
' Add client stored in NewData argument to the client table.
Set dbsMyDatabase = CurrentDb
Set rstClients = dbsMyDatabase.OpenRecordset("tbl 1 Client")
rstClients.AddNew
rstClients!ClientID = NewData
rstClients.Update
Response = acDataErrAdded ' Requery the combo box list.
DoCmd.OpenForm stdocName, , , stLinkCriteria, acAdd, acDialog, NewData
Else
Response = acDataErrDisplay ' Require the user to select an
existing client.
Me.cboClient = Null
End If
Set rstClients = Nothing
Set dbsMyDatabase = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
Then, in the Load event of the data entry form:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me![ClientID] = Me.OpenArgs
End If
End Sub
This code does add the record, but I am unable to retain the data I enter on
the data entry form. Also, I will have subform(s) that I will need to be
adding data to (they will have their own table.)
What have I done wrong?
How do I get data in the client table?
Then, how do I get data into the suborm's tables?
Help is very much appreciated.
Chrissy
Using NotInList event for a client selector combo box I add a new record for
a client and open a data entry form to enter data for a new (previously
non-existent client).
Using the code below I add the record to my client table, but no data (other
than that key field) stays in the table.
Code attached to NotInList event:
Dim dbsMyDatabase As DAO.Database
Dim rstClients As DAO.Recordset
Dim intAnswer As Integer
Dim stdocName, stLinkCriteria As String
stdocName = "1frmDEClient"
stLinkCriteria = "[ClientID]=" & "'" & NewData & "'"
NewData = UCase(NewData)
On Error GoTo ErrorHandler
intAnswer = MsgBox("Add " & NewData & " to the list of Clients?", _
vbQuestion + vbYesNo)
If intAnswer = vbYes Then
' Add client stored in NewData argument to the client table.
Set dbsMyDatabase = CurrentDb
Set rstClients = dbsMyDatabase.OpenRecordset("tbl 1 Client")
rstClients.AddNew
rstClients!ClientID = NewData
rstClients.Update
Response = acDataErrAdded ' Requery the combo box list.
DoCmd.OpenForm stdocName, , , stLinkCriteria, acAdd, acDialog, NewData
Else
Response = acDataErrDisplay ' Require the user to select an
existing client.
Me.cboClient = Null
End If
Set rstClients = Nothing
Set dbsMyDatabase = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
Then, in the Load event of the data entry form:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me![ClientID] = Me.OpenArgs
End If
End Sub
This code does add the record, but I am unable to retain the data I enter on
the data entry form. Also, I will have subform(s) that I will need to be
adding data to (they will have their own table.)
What have I done wrong?
How do I get data in the client table?
Then, how do I get data into the suborm's tables?
Help is very much appreciated.
Chrissy