Solved

Button to pick record..

Posted on 2004-08-31
23
277 Views
Last Modified: 2008-03-17
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.
0
Comment
Question by:plimpias
  • 9
  • 6
  • 4
  • +1
23 Comments
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11944232
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
 
LVL 5

Expert Comment

by:Emanon_Consulting
ID: 11944348
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
 
LVL 15

Author Comment

by:plimpias
ID: 11944489
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11944527
What is the "Record Locks" property of your "New_Project" form set to?
0
 
LVL 15

Author Comment

by:plimpias
ID: 11944617
Allrecords. Does it matter if the project # is in a subform within the New_Project form?
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11944663
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
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11944679
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
 
LVL 15

Author Comment

by:plimpias
ID: 11944694
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
 
LVL 5

Expert Comment

by:Emanon_Consulting
ID: 11944756
The proper syntax for pointing to a Subform is this

Forms!Mainform!Subform1.Form!Subform2.Form!ControlName
0
 
LVL 5

Expert Comment

by:Emanon_Consulting
ID: 11944765
Sorry that's if you have two embedded subforms.  Here's the syntax for 1 subform
Forms!Mainform!Subform1.Form!ControlName
0
 
LVL 5

Expert Comment

by:Emanon_Consulting
ID: 11944801
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11945577
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
 
LVL 15

Author Comment

by:plimpias
ID: 11948279
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11948381
plimpias, have you tried the code I gave you?
0
 
LVL 15

Author Comment

by:plimpias
ID: 11948409
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11948443
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
 
LVL 15

Author Comment

by:plimpias
ID: 11948493
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
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 250 total points
ID: 11948554
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
 
LVL 15

Author Comment

by:plimpias
ID: 11948742
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11948785
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
 
LVL 15

Author Comment

by:plimpias
ID: 11948804
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11948858
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
 
LVL 15

Author Comment

by:plimpias
ID: 11948937
Ahh data entry was set to yes on the form. Damn that data entry!

Thanks for the help
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now