Results 1 to 10 of 10
  1. #1
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727

    Form Button With Macro To Open Another Form

    So I have this button on a form called "Movie Query" that will open another form called "By Genre". By Genre is linked to a query that searches by genre. I have this query set up to ask the user to enter a genre to start the query by using an expression in the criteria part of the query [Enter Genre:]. The macro that is being used on the button is set "On Click" to open this second query/form, By Genre, then to close the current form, Movie Query. However, if the user clicks cancel when prompted for the genre entry, it will still close the Movie Query form. I would like it to cancel the closewindow macro if the user clicks on cancel.

    I think I need an IF macro but I'm not sure how to use it. Can someone explain if that is what I need or is there something else I can do? If so, can you explain how to use the IF macro action.

    Thanks.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Your code to close the original form, if that is what is happening, will not wait for the user to make a decision to cancel or not. As far as I know you will have to remove the argument from the parameterized query and incorporate it into your form so you can manage the user's input or lack thereof.

  3. #3
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Thank you. I think I know what you mean. Or at least you gave me an idea.

    I'm going to add the close window action to the form being opened to close the previous window.

    Don't know why I didn't think of that before. I must have been really tired last night.

    Thanks.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe you can use a msgbox with that. You can get input from the user using Input() but I would recommend using an unbound control. You can pass that value in a public variable or in open args.

  5. #5
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Well that didn't work either so what I did was enter the closewindow macro in the "On Got Focus" property of my By Genre form. So now if you click the By Genre button in the Movie Query form, you can hit cancel and nothing will happen because I took out the closewindow macro for this button. Then if you do enter the genre it will take you to By Genre form and I guess when it gets the focus of the By Genre window, it executes the closewindow macro for the Movie Query form. I'm just guessing thats what happens since I don't really understand what On Got Focus really means.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Choosing the correct event is important. Also, I will imagine evaluating user input via a message box will be difficult, at least, using a macro.

  7. #7
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Tell me about it. Thanks for your help though. Appreciate it.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is one example of using VBA to create a msgbox.

    Code:
    Dim intResponse as Integer
    intResponse = MsgBox ("Any data you entered will not be saved!", vbOKCancel)
    If intResponse = vbCancel Then
     Undo
    DoCmd.Close acForm, "NameOfForm"
    elseIf intResponse = vbOK Then
    Exit Sub
    End If

  9. #9
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Thanks Itsme.

    I have a vba that asks the user if they want to save when closing a window if the data was altered.

    Do you know what the On Dirty and On Got Focus properties mean? Or have some examples of how to use it?

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Got focus will fire when the user has focus, anytime, when it first happens. So the user could tab to a control and fire On Got Focus or click the control....

    I don't think I have used the On Dirty. I would imagine this would happen when a control loses focus AND the value changed. Dirty = true indicates the form's recordset has changed but not fully committed yet. The undo might reverse this Dirty state, for instance. Most people prefer to do validation in the BeforeUpdate event handler.

    BeforeUpdate can be associated to an individual control or the entire form. So, depending on what values you need to validate, you have a choice of a specific field, the entire form, or a combination of both. The BeforeUpdate event also has an option to cancel; Cancel = True (in case a condition is found to be not favorable). In general, BeforeUpdate offers concise control for evaluation of the value.

    Edit: I noticed that there is an example of undo in the code provided. Undo can sometimes have unpredictable results (if not used cautiously). My intention was to provide an example of a msgbox and not advocate the use of undo. Using Cancel = true in the BeforeUpdate is preferred when choosing not to save a record. Regardless, you need to do your evaluations at the correct places and times. This takes planning.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2013, 04:23 PM
  2. Replies: 2
    Last Post: 05-11-2012, 11:52 AM
  3. Replies: 7
    Last Post: 05-01-2012, 11:43 AM
  4. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  5. Replies: 3
    Last Post: 10-16-2009, 07:54 AM

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