Linking popup form to main form

adrienne_r30

Registered User.
Local time
Today, 03:13
Joined
Jan 20, 2015
Messages
48
I have a 'main' table with a Project_Number that links all the data in my db together. I have another table that uses that Project_Number as a lookup field to connect that tables data to the main data. I created a 'main' form that has the ability to enter data for the 'main' table. I want to be able to press a button and have the second tables form pop up and add that that specific Project_Number. I added the button and went through the wizard process. I then added the linking info through the builder. It works fine if there is already data entered for the project_number in that specific field. but if the field is empty, the popup window doesn't recognize a project_number and doesn't add it to that record. below is what I am using. The project_number in the 'main' table is text and the Project_Number in the 2nd table in a number since it is a lookup field.

Private Sub CongressionalDistrictCmd_Click()
On Error GoTo Err_CongressionalDistrictCmd_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sbfrm_Congressional_District"

stLinkCriteria = "[Project_Number]='" & Me.[Project_Number] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_CongressionalDistrictCmd_Click:
Exit Sub
Err_CongressionalDistrictCmd_Click:
MsgBox Err.Description
Resume Exit_CongressionalDistrictCmd_Click

End Sub



I'm am getting really frustrated, please HELP!!

Thanks
 
So, are you saying if there is no Project Number the Pop-Up fails? If so, what do you want to happen?
 
no. the 'main' form it self shows all the info for one project_number. I can click through the record selector below and go to the next project number record. inside this form is a box that shows all of the districts that covers this project. if there is already a district defined, the popup opens and I can add more districts and it saves to the 'main' form just fine. but if there is no district and I want to add a district, the popup opens, I add the district but it doesn't save to the 'main' form. when I open the table it is associated with, my selection is there, but with a blank project_number. so it is saving my selection but it is not recognizing the project_number if the field is initially blank
 
Hmm, okay, well in the Before_Update event of the Pop-Up Form try adding...

Code:
Me.[Project_Number] = Forms![NameOfMainForm]![Project_Number]
 
that doesn't seem to work for me. Do you think I should put something like that in my onopen function?
 
It should not be in the On_Open event it should be on the Before Update event of the newly opened Form. When you say it does not work what exactly does that mean... what happen?
 
nothing happened. I put the info in the popup form for a blank field and it still did not update for that project_number, but it went into its table with no project_number associated with it.
 
Please post exactly what you pasted in the [Event Procedure] here...
 
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.Project_Number = Forms![frm_Main_Data_Entry]![Project_Number]
End Sub
 
And when you type something in any other field it's not storing the number? It won't show till you actually enter something. If that is the case, please confirm the *name* of the Controls you are referencing.
 

Users who are viewing this thread

Back
Top Bottom