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]![Project #].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.
LVL 15
plimpiasAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
shanesuebsahakarnConnect With a Mentor Commented:
Because the name has a - sign in it, you need to enclose it in [], like so:

Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "New_Project"
   
    stLinkCriteria = "[Project #]=" & "'" & Me![Project #] & "'"
DoCmd.OpenForm stDocName
Forms(stDocName)![SF-NewProject].Form.Filter = strLinkCriteria
Forms(stDocName)![SF-NewProject].Form.FilterOn = True
0
 
will_scarlet7Commented:
Check out this thread:
    http://www.experts-exchange.com/Databases/MS_Access/Q_21111240.html

I think it is discussing exactly what you are trying to do.

God bless!

Sam
0
 
Emanon_ConsultingCommented:
Try changing your syntax from this
    Form![New_Project]![Project #].Visible = True

to this
    Forms![New_Project]![Project #].Visible = True

It might be what is giving you the error...

Cheers
M
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
plimpiasAuthor Commented:
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.
0
 
will_scarlet7Commented:
What is the "Record Locks" property of your "New_Project" form set to?
0
 
plimpiasAuthor Commented:
Allrecords. Does it matter if the project # is in a subform within the New_Project form?
0
 
will_scarlet7Commented:
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"
0
 
will_scarlet7Commented:
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.
0
 
plimpiasAuthor Commented:
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
0
 
Emanon_ConsultingCommented:
The proper syntax for pointing to a Subform is this

Forms!Mainform!Subform1.Form!Subform2.Form!ControlName
0
 
Emanon_ConsultingCommented:
Sorry that's if you have two embedded subforms.  Here's the syntax for 1 subform
Forms!Mainform!Subform1.Form!ControlName
0
 
Emanon_ConsultingCommented:
Something like this?

    stLinkCriteria = "Forms!Mainform!Subform1.[New_Project]![Project #]=" & "'" & Me![Project #] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms!Mainform!Subform1.[New_Project]![Project #].Visible = True

Cheers
M
0
 
shanesuebsahakarnCommented:
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)!MySubformControl.Form.Filter=strLinkCriteria
Forms(stDocName)!MySubformControl.Form.FilterOn=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.
0
 
plimpiasAuthor Commented:
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_Poject.[New_Poject]![Project #]=" & "'" & Me![Project #] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms!New_Poject!SF-New_Poject.[New_Poject]![Project #].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
0
 
shanesuebsahakarnCommented:
plimpias, have you tried the code I gave you?
0
 
plimpiasAuthor Commented:
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?
0
 
shanesuebsahakarnCommented:
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.
0
 
plimpiasAuthor Commented:
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-NewProject.Form.Filter = strLinkCriteria
Forms(stDocName)!SF-NewProject.Form.FilterOn = True

Its giving a compile error (santax error) and highlights the row
Forms(stDocName)!SF-NewProject.Form.Filter = strLinkCriteria
0
 
plimpiasAuthor Commented:
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.
0
 
shanesuebsahakarnCommented:
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)?
0
 
plimpiasAuthor Commented:
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.
0
 
shanesuebsahakarnCommented:
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)?
0
 
plimpiasAuthor Commented:
Ahh data entry was set to yes on the form. Damn that data entry!

Thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.