Default value in forms

SueBK

Registered User.
Local time
Tomorrow, 09:10
Joined
Apr 2, 2009
Messages
197
At the beginning of my database the user chooses a project to work on. Everything (forms/reports) they open from then on filters against that project. (The common field in all the relevant tables is "ProjectID") If they create new record; however, they have to enter the project number into the record.

How do I set it so new records automatically enter the currently filtered project into the project ID field of the table being modified?
 
The default value can be a form reference to the form control containing the selected ProjectID.
 
I don't follow. Sorry to be dense. It's Monday am.

In the header of my form I have a combo box called "ProjectID", which is filtered to the selected project. The filter is code attached to the command button that opens the form.

I then have a 2nd combo box in my details that section; and this is the one I want to set a default value of whatever is in the header.

I gather you're saying to reference my default value in the 2nd combo box to the value of the 1st one. But I'm not sure how to do that.
 
There's your first problem; it's still Sunday pm. :p

Try this as the default value:

Forms!FormName.ComboName
 
I think I know why it's not working for me, but I don't know why it's not working :-)

When I click in a new record (it's a continuous form), the combobox in the header (the one showing the filtered project #) goes blank.

SO:
On "Form 01" I have a command button that opens "frmKeyActivities". The code is:

Code:
Private Sub Command261_Click()
On Error GoTo Err_Command261_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmKeyActivities"
stfilter = "[ProjectID]=" & Str(Me.ProjectID)
DoCmd.OpenForm stDocName, , , stfilter
Exit_Command261_Click:
Exit Sub
Err_Command261_Click:
MsgBox Err.Description
Resume Exit_Command261_Click
 
End Sub

In "frmKeyActivities" the form property filter comes up as "[ProjectID]= 1" (with the number changing depending on what project was chosen on Form 01.

All the records showing are filtered to the Project ID chosen on Form 01; but NEW records aren't filtering against anything. As I said, the combo box showing the filtered number goes blank.

Therefore - I suspect my issue with having a default value in the new record is the manner in which the initial filtering is done.
 
Can you post the db? I can't think offhand of why the combo would go blank.
 
Would love to, but its nearly 40MB and full of confidential information <sigh>. I'll keep trying to muddle through with the hints you've given me. I'll check other forms and see if they drop the filtered box as well. Maybe I'll hit one that doesn't and go from there :)
 
Okay, found a work around, and possibly an answer as to why the field in the heading changes. The current box in the header of most of my forms is bound to a field in the table; so when you go to a new record - there's no data for it to pick up.

First - in the open form command button I've added the ProjectID to the openargs on the filtering code.

Second - on the form open command I've dumped the openargs contents into a text box on the form header.

Third - I've closed all forms to additions; added a "new record" command button. The new record command allows additions; creates a new record; dumps the contents of the text box from the header into the relevant field in the record; and then disallows additions.

Maybe, code wise, its a bit clumsy, but it works :-) And at the moment - that's all I care!
 

Users who are viewing this thread

Back
Top Bottom