Problem with Form to Subform Code

RichardP1978

Registered User.
Local time
Today, 02:14
Joined
Nov 14, 2006
Messages
89
I have a main form, which has a subform on it.

THe Main form is the main page for the clients, and the subform holds hyperlinks to PDF files (letters we have recieved on a client). This works fine.

I am trying to get it so when a document gets inserted in to the subform, a date is automatically inserted in to a field.

When testing the subform on its own, opened directly from the database window, it inserts the date with no problem. However, when trying to do the same in the subform when it is opened as part of the main form, VBA crashes out saying it cant find the subform.

I think I understand why it is crashing out, as the subform isnt actually open open, but its a case of how do I reference it.

This is the code that I am trying to use, which as I said works fine when the subform is opened exclusively, not through the main form.

Hope someone can help.

If IsNull(Forms![subfrmDocuments]![DocumentAddedDate]) = True Then
Forms![subfrmDocuments]![DocumentAddedDate] = Date
Else
End If
 
Why not just set the Default value of your date field to =Date() ?
 
Because on occassion the document may be moved about on the server and then the date would be a new date, not an old one, and it needs to be the date the document was originally put on the system.

Hope that makes sense.
 
I have sussed it.

Finally found something, just as always after one posts the question, the very next click you find the answer.

This is the code that now works

If IsNull(Forms![frmclientmain]!subfrmDocuments.Form![DocumentAddedDate]) = True Then
Forms![frmclientmain]!subfrmDocuments.Form![DocumentAddedDate] = Date
Else
End If

I found it here if it is of any use to someone else.

http://www.mvps.org/access/forms/frm0031.htm
 

Users who are viewing this thread

Back
Top Bottom