plimpias
asked on
Button to pick record..
I have a form that list company names, all the records have a button called view. The button opens the projects that are a part of the company.
Here is the code for the button
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err
If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If
ToggleLink_Click_Exit:
Exit Sub
ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit
End Sub
This part works fine. It is filtering the projects that belong only to the company i pick
But i am trying to add a new button on this form that will bring up that project # in my project # form so i can edit it? how can i do this.
I was trying
Private Sub Command3_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Project"
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Form![New_Project]![Projec t #].Visible = True
Exit_Command25_Click:
Exit Sub
Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End Sub
but that prompted my for a project # then errored out.
Here is the code for the button
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err
If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If
ToggleLink_Click_Exit:
Exit Sub
ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit
End Sub
This part works fine. It is filtering the projects that belong only to the company i pick
But i am trying to add a new button on this form that will bring up that project # in my project # form so i can edit it? how can i do this.
I was trying
Private Sub Command3_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Project"
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Form![New_Project]![Projec
Exit_Command25_Click:
Exit Sub
Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End Sub
but that prompted my for a project # then errored out.
Try changing your syntax from this
Form![New_Project]![Projec t #].Visible = True
to this
Forms![New_Project]![Proje ct #].Visible = True
It might be what is giving you the error...
Cheers
M
Form![New_Project]![Projec
to this
Forms![New_Project]![Proje
It might be what is giving you the error...
Cheers
M
ASKER
Gives me the same thing says enter paremeter value, aks for project # then if i enter one in it give a run time error. You tried to lock table " while opening it, but the table cannot be locked becuase it is currently in use. Wait a moment, and then try the operation again.
What is the "Record Locks" property of your "New_Project" form set to?
ASKER
Allrecords. Does it matter if the project # is in a subform within the New_Project form?
Just a guess from reading the error that you posted...
Change the Record Locks property for your form (New_Project), to either "No Locks" or "Edited Record" and see if that fixes it.
You might also need to change the Record Locks property on your form that is "filtering the projects that belong only to the company i pick"
Change the Record Locks property for your form (New_Project), to either "No Locks" or "Edited Record" and see if that fixes it.
You might also need to change the Record Locks property on your form that is "filtering the projects that belong only to the company i pick"
I think it is that one of your other forms is using that same record, therefore it cannot open another form that has Allrecords locked while the first form is open.
ASKER
OK i changed to no locks. the form where in button was had no locks on. Now im getting a error can't fine project # referred to in your expression? how can i point this expression to point to my subform and not my main form? the main form doesn't have the project # field in it, the subform does. also will this fix the peremeter value box it get?
Increasing this to 150...thanks
Increasing this to 150...thanks
The proper syntax for pointing to a Subform is this
Forms!Mainform!Subform1.Fo rm!Subform 2.Form!Con trolName
Forms!Mainform!Subform1.Fo
Sorry that's if you have two embedded subforms. Here's the syntax for 1 subform
Forms!Mainform!Subform1.Fo rm!Control Name
Forms!Mainform!Subform1.Fo
Something like this?
stLinkCriteria = "Forms!Mainform!Subform1.[ New_Projec t]![Projec t #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Mainform!Subform1.[N ew_Project ]![Project #].Visible = True
Cheers
M
stLinkCriteria = "Forms!Mainform!Subform1.[
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!Mainform!Subform1.[N
Cheers
M
If this is the case:
> Does it matter if the project # is in a subform within the New_Project form?
You need something like this:
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName
Forms(stDocName)!MySubform Control.Fo rm.Filter= strLinkCri teria
Forms(stDocName)!MySubform Control.Fo rm.FilterO n=True
I assume your main form is unbound, or the subform and main form aren't related on the Project # field. MySubformControl needs to be the name of the control that the subform is contained in, not the subform's name.
> Does it matter if the project # is in a subform within the New_Project form?
You need something like this:
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName
Forms(stDocName)!MySubform
Forms(stDocName)!MySubform
I assume your main form is unbound, or the subform and main form aren't related on the Project # field. MySubformControl needs to be the name of the control that the subform is contained in, not the subform's name.
ASKER
I get compile error:
Syntax error
Here is the code i am using
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Poject"
stLinkCriteria = "Forms!New_Poject!SF-New_P oject.[New _Poject]![ Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!New_Poject!SF-New_Po ject.[New_ Poject]![P roject #].Visible = True
I created my form with the wizard. It is 2 fields from two different tables. It is a linked type form.
Raisen the points to 250
Thanks for the posts
Syntax error
Here is the code i am using
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Poject"
stLinkCriteria = "Forms!New_Poject!SF-New_P
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!New_Poject!SF-New_Po
I created my form with the wizard. It is 2 fields from two different tables. It is a linked type form.
Raisen the points to 250
Thanks for the posts
plimpias, have you tried the code I gave you?
ASKER
No i didn't i'll try it right now. What do you mean by the name of the control that the subform is contained in?
Design the main form. Click on the subform and bring up the Properties window (View->Properties). Check that the title of the Properties window says "Subform/Subreport: <something>". Click in the Other page. The Name property is the name of the subform control. Basically, when a form is a subform, it sits inside a subform control, and that's what you need to refer to in this case.
ASKER
I noticed that the name was different. But i changed it to SF-NewProject
the code now reads as
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Project"
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName
Forms(stDocName)!SF-NewPro ject.Form. Filter = strLinkCriteria
Forms(stDocName)!SF-NewPro ject.Form. FilterOn = True
Its giving a compile error (santax error) and highlights the row
Forms(stDocName)!SF-NewPro ject.Form. Filter = strLinkCriteria
the code now reads as
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "New_Project"
stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName
Forms(stDocName)!SF-NewPro
Forms(stDocName)!SF-NewPro
Its giving a compile error (santax error) and highlights the row
Forms(stDocName)!SF-NewPro
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK it works great but for some reason i have to hit the button twice in order to get the form to display the poject #. If i hit it once it opens the form and it is blank, then i hit it again and it opens the project #, after it does the first hit blank i can scroll through the rest of them fine.
When you say it's blank, do you mean it has no records in it, or it's completely blank (i.e. no controls or anything on it at all)?
ASKER
no just no records in it...and when i hit the button again...the second time the record shows up correclty. I think the form has to be open for the code to work. Because when it is closed it doesn't work. After it is open it works good.
What's the recordsource of the main form, and how is it linked to the subform (i.e. what are the child and master fields)?
ASKER
Ahh data entry was set to yes on the form. Damn that data entry!
Thanks for the help
Thanks for the help
https://www.experts-exchange.com/questions/21111240/OPENING-FILTERED-FORM-FROM-A-UNION-QUERY.html
I think it is discussing exactly what you are trying to do.
God bless!
Sam