S
Suzy
Here are my problems...
1. I am a beginner user of Access and I’m in *way* over my head setting up
a client database for my sister’s beauty therapy business.
2. With the held of some very helpful advice from this Group I have
achieved various tables, queries, macros, forms and reports. But now I’m
stuck! With help I have set a form up where client notes can be entered
following each visit and updated with an ongoing client history. This all
works great, until I want to enter a note for a first time client (ie the
client does not have any earlier notes in the history), when I get the
following run time error '3201': "You cannot add or change a record because a
related record is required in table ‘StaffInfo’. "
When I choose to 'debug' I am taken through to the Visual Basic window which
is highlighting the code "DoCmd.RunCommand acCmdSaveRecord 'forces record
save" as the problem.
Where am I going wrong?? I appreciate your ('idiots guide to') help with
this problem as I am in *way* over my head! Here’s the advice I have been
given previously and which I have used to set up this feature…
Two tables:
1. StaffInfo
Field1: ClientID (primary key, autonumber, long integer)
Field2: FirstName (text)
Field3: LastName (text)
Field4: Title (text)
Etc (other client details)
2. ClientNotes
Field1: ID (Primary key, autonumber, long integer)
Field2: ClientID (long integer, no default)
Field3: Notes (memo)
Create a relationship (enforce referential integrity, cascade update on)
between the two tables on the ClientID field.
Form: PostClientNotes. Default view: Single form. Record source (copy &
paste this into the record source, then look at the query design view using
the ellipsis to see how it was constructed):
SELECT ClientNotes.* FROM ClientNotes WHERE
(((ClientNotes.ClientID)=[Forms]![PostClientNotes]![ClientIDSelector]));
In the form's detail section, create an UNBOUND combo box called
ClientIDSelector.
ColumnCount = 4, BoundColumn = 1, ColumnWidths = 0cm;2.501cm;3cm;1.51cm.
RowSource is:
SELECT StaffInfo.ClientID, StaffInfo.FirstName, StaffInfo.LastName,
StaffInfo.Title FROM StaffInfo ORDER BY StaffInfo.FirstName,
StaffInfo.LastName, StaffInfo.Title;
This code goes into its AfterUpdate event:
Private Sub ClientIDSelector_AfterUpdate()
Me.Requery 'display Notes for selected Customer
End Sub
Also in the form detail, create the UNBOUND NoteNew text box. Be sure to set
the Enter key behavior to New Line in Field for this text box so that the
user can enter multiple lines in one entry.
Also in the form detail, create a button called PostNotes. Put this code in
its Click event:
Private Sub PostNotes_Click()
If IsNull(NoteNew) Or NoteNew = "" Then Exit Sub
If IsNull(Notes) Then 'do not insert blank line after new note
Notes = Date & Chr(13) & Chr(10) & [NoteNew]
Else 'insert blank line between existing note and new note
Notes = Date & Chr(13) & Chr(10) & [NoteNew] & Chr(13) & Chr(10) & Chr(13) &
Chr(10) & [Notes]
End If
NoteNew = Null 'blanks out new note, since it was just appended to Notes entry
DoCmd.RunCommand acCmdSaveRecord 'forces record save
End Sub
Lastly in the form's detail section, create a single bound but disabled text
box called Notes. Its ControlSource is just Notes (i.e. the Notes field).
Create a query called PostClientNotes. Go to SQL view & paste in this:
TO PUT NEW NOTES AT THE TOP OF THE MEMO:
UPDATE ClientNotes SET ClientNotes.Notes = Date() & Chr(13) & Chr(10) &
[Notes] & [Forms]![PostClientNotes]![NoteNew]
WHERE
(((ClientNotes.ClientID)=[Forms]![PostClientNotes]![ClientIDSelector])) &
Chr(13) & Chr(10) & [Notes];
Now, here is what happens. When a user opens the form, it is blank. When the
user selects a Client by Client name from the combo box at the top, it shows
that Clients Notes field from the ClientNotes table. The user can then enter
notes into the NoteNew text box and clicks the button. If the NotesNew field
or ClientIDSelector are null/empty, it does nothing (to prevent an error if
there is nothing to append). If there are NotesNEw, this udpates the existing
Notes field to be:
1. Current date
2. Followed by a linefeed
3. Followed by the new notes
4. Followed by another linefeed
5. Followed by existing notes
The code on the button then clears the new notes field and resets the form
so that the new consolidated note appears in the Notes text box.
1. I am a beginner user of Access and I’m in *way* over my head setting up
a client database for my sister’s beauty therapy business.
2. With the held of some very helpful advice from this Group I have
achieved various tables, queries, macros, forms and reports. But now I’m
stuck! With help I have set a form up where client notes can be entered
following each visit and updated with an ongoing client history. This all
works great, until I want to enter a note for a first time client (ie the
client does not have any earlier notes in the history), when I get the
following run time error '3201': "You cannot add or change a record because a
related record is required in table ‘StaffInfo’. "
When I choose to 'debug' I am taken through to the Visual Basic window which
is highlighting the code "DoCmd.RunCommand acCmdSaveRecord 'forces record
save" as the problem.
Where am I going wrong?? I appreciate your ('idiots guide to') help with
this problem as I am in *way* over my head! Here’s the advice I have been
given previously and which I have used to set up this feature…
Two tables:
1. StaffInfo
Field1: ClientID (primary key, autonumber, long integer)
Field2: FirstName (text)
Field3: LastName (text)
Field4: Title (text)
Etc (other client details)
2. ClientNotes
Field1: ID (Primary key, autonumber, long integer)
Field2: ClientID (long integer, no default)
Field3: Notes (memo)
Create a relationship (enforce referential integrity, cascade update on)
between the two tables on the ClientID field.
Form: PostClientNotes. Default view: Single form. Record source (copy &
paste this into the record source, then look at the query design view using
the ellipsis to see how it was constructed):
SELECT ClientNotes.* FROM ClientNotes WHERE
(((ClientNotes.ClientID)=[Forms]![PostClientNotes]![ClientIDSelector]));
In the form's detail section, create an UNBOUND combo box called
ClientIDSelector.
ColumnCount = 4, BoundColumn = 1, ColumnWidths = 0cm;2.501cm;3cm;1.51cm.
RowSource is:
SELECT StaffInfo.ClientID, StaffInfo.FirstName, StaffInfo.LastName,
StaffInfo.Title FROM StaffInfo ORDER BY StaffInfo.FirstName,
StaffInfo.LastName, StaffInfo.Title;
This code goes into its AfterUpdate event:
Private Sub ClientIDSelector_AfterUpdate()
Me.Requery 'display Notes for selected Customer
End Sub
Also in the form detail, create the UNBOUND NoteNew text box. Be sure to set
the Enter key behavior to New Line in Field for this text box so that the
user can enter multiple lines in one entry.
Also in the form detail, create a button called PostNotes. Put this code in
its Click event:
Private Sub PostNotes_Click()
If IsNull(NoteNew) Or NoteNew = "" Then Exit Sub
If IsNull(Notes) Then 'do not insert blank line after new note
Notes = Date & Chr(13) & Chr(10) & [NoteNew]
Else 'insert blank line between existing note and new note
Notes = Date & Chr(13) & Chr(10) & [NoteNew] & Chr(13) & Chr(10) & Chr(13) &
Chr(10) & [Notes]
End If
NoteNew = Null 'blanks out new note, since it was just appended to Notes entry
DoCmd.RunCommand acCmdSaveRecord 'forces record save
End Sub
Lastly in the form's detail section, create a single bound but disabled text
box called Notes. Its ControlSource is just Notes (i.e. the Notes field).
Create a query called PostClientNotes. Go to SQL view & paste in this:
TO PUT NEW NOTES AT THE TOP OF THE MEMO:
UPDATE ClientNotes SET ClientNotes.Notes = Date() & Chr(13) & Chr(10) &
[Notes] & [Forms]![PostClientNotes]![NoteNew]
WHERE
(((ClientNotes.ClientID)=[Forms]![PostClientNotes]![ClientIDSelector])) &
Chr(13) & Chr(10) & [Notes];
Now, here is what happens. When a user opens the form, it is blank. When the
user selects a Client by Client name from the combo box at the top, it shows
that Clients Notes field from the ClientNotes table. The user can then enter
notes into the NoteNew text box and clicks the button. If the NotesNew field
or ClientIDSelector are null/empty, it does nothing (to prevent an error if
there is nothing to append). If there are NotesNEw, this udpates the existing
Notes field to be:
1. Current date
2. Followed by a linefeed
3. Followed by the new notes
4. Followed by another linefeed
5. Followed by existing notes
The code on the button then clears the new notes field and resets the form
so that the new consolidated note appears in the Notes text box.