Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232

    command button

    I have a form name “proposals” I have a command button that opens up a formcalled “service”
    I would like when I click the command button that when theform “service” opens then is will auto fill the fields “Proposal” based onfollowing
    Field “optionOne” and field OptionTwo they are both yes/noand I have it set up so that only on can be yes. Each has it own Proposal field . So which ever option is yes that is theproposal that I want to show on the form service under proposal.

    IIf me.optionOne = true then
    Forms[service]![proposal] = proposalOne
    Else
    Me.optionsTwo = true then


    Forms[service]![proposal]= proposalTwo
    End IIF

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    More like

    Code:
    If me.optionOne = true then
      Forms[service]![proposal] = proposalOne
    ElseIf Me.optionsTwo = true then
      Forms[service]![proposal]= proposalTwo
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Do I place this code into the on click in the command button to open the form? if I do that it will delete the on click marco to open the service form.
    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can add a line opening the form before that bit.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    I added this to the command button to open the form " But I get the error block if without end if
    , it highlights the end sub
    not sure how to fix


    Private Sub Command125_Click()
    On Error GoTo Command125_Click_Err
    DoCmd.OpenForm "Service Calls From Proposals", acNormal, "", "[CustomerID]=" & [CustomerID], , acNormal
    Command125_Click_Exit:
    Exit Sub
    Command125_Click_Err:
    MsgBox Error$
    Resume Command125_Click_Exit

    If Me.OptionOne = True Then
    Form![serviceCallsFromProposals]![Proposal] = ProposalDescripition
    Else
    If Me.OptionTwo = True Then
    Form![serviceCallsFromProposals]![Proposal] = proposalDescripitionTwo
    End If


    End Sub

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    A "block" is a section of code that must begin with a specific opening statement and a corresponding closing statement. Another example is
    Select Case something
    ...bunch of code
    End Select

    You have an un-paired IF. One way to eliminate it is, don't break up the IF's when it's not necessary. Seems not here, but I can't be 100% sure.
    If Me.OptionOne = True Then Form![serviceCallsFromProposals]![Proposal] = ProposalDescripition
    If Me.OptionTwo = True Then Form![serviceCallsFromProposals]![Proposal] = proposalDescripitionTwo
    Or you could check out the ElseIF construct.

    EDIT: True is sort of a default for a Boolean value. If Me.OptionTwo Then... is the same as what you wrote.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That's not the code I gave you, and belongs immediately after the OpenForm line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Error when I try this, the highlighted shows that it can not find the field.

    Private Sub Command125_Click()

    DoCmd.OpenForm "Service Calls From Proposals", acNormal, "", "[CustomerID]=" & [CustomerID], , acNormal

    If Me.OptionOne = True Then
    Form![serviceCallsFromProposals]![Proposal] = ProposalDescripition

    ElseIf Me.OptionTwo = True Then
    Form![serviceCallsFromProposals]![Proposal] = proposalDescripitionTwo
    End If


    End Sub

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The form name has spaces in one line, not in the other.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    This is still not working....it highlights the 4th line and it is error "cant find the field "serviceCallsProposals"


    Private Sub CREATE_SERVICE_CALL_BUTTON_DblClick(Cancel As Integer)
    DoCmd.OpenForm "ServiceCallsProposals", acNormal, "", "[CustomerID]=" & [CustomerID], , acNormal
    If Me.OptionOne = True Then
    Form![serviceCallsProposals]![Proposal] = ProposalDescription
    ElseIf Me.OptionTwo = True Then
    Form![serviceCallsProposals]![Proposal] = ProposalDescriptionTwo
    End If
    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    It's Forms, not Form. The other line will error too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Thank you pbaldy,,,, that works great
    have a wonderful day
    Angie

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    @angie: I had to go back to my post hoping that it was you who dropped the s but it was me. My apologies.
    However I am in good company because it's not Forms[ either: Forms[service]![proposal]= proposalTwo

    I also see another potential issue in that you can't put a vague reference on one side of a comparison.
    This = proposalDescripitionTwo is located where? It either needs the full Forms! reference or Me but I can't tell which because its location is unknown.


    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I never did that! Somebody edited my post and took out the bangs! I was so focused on the If/Then syntax I didn't notice that.

    On the vague reference, I wouldn't say "can't", but I would say "shouldn't". Access will allow it and might be able to work out whether it's a variable or field/control on the form. It certainly wouldn't be able to work it out if it was on a different form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-29-2015, 07:42 PM
  2. Replies: 1
    Last Post: 09-12-2014, 06:09 AM
  3. Replies: 3
    Last Post: 08-04-2013, 07:11 AM
  4. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  5. Command Button Help!
    By arthura in forum Programming
    Replies: 3
    Last Post: 06-30-2009, 12:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums