View Full Version : Double clicking sub-form to add data


twobit94
03-15-2000, 05:18 AM
I am trying to make a subform that you can double click and be able to add data (via a form) to the table refered to in the sub -form.

The database is for a library and the subform is for topics. The subform allows the user to select multiple topics for the same book, however, if a topic is not already entered in the topic table then I want to be able to enter by double clicking the subform and have the topic table open in entry mode.

I appreciate any assistance.

Brian

Carol
03-15-2000, 02:57 PM
On your main form Field "Topic" insert this procedure On Dbl Click:

Private Sub Topic_DblClick(Cancel As Integer)
On Error GoTo Err_Topic_DblClick
Dim lngTopic As Long

If IsNull(Me![Topic]) Then
Me![Topic].Text = ""
Else
lngTopic = Me![Topic]
Me![Topic] = Null
End If
DoCmd.OpenForm "Topic", , , , , acDialog, "GotoNew"
Me![Topic].Requery
If lngTopic <> 0 Then Me![Topic] = lngTopic

Exit_Topic_DblClick:
Exit Sub

Err_Topic_DblClick:
MsgBox Err.Description
Resume Exit_Topic_DblClick
End Sub
-----------------------------
Insert this code at the On Not in List:

Private Sub Topic_NotInList(NewData As String, Response As Integer)
MsgBox "Double-click this field to add an entry to the list."
Response = acDataErrContinue
End Sub


You will have to change the field and table names accordingly as I have assumed that the field name in the main form is called topic and your subform for adding new is also called topic.

Good luck.