Running code after a Yes/No response

Why open Project Log Sheet when it is already open?
 
This is my code, what i am doing wrong?

Public Sub Add_new_request_Click()

DoCmd.OpenForm ("Project Log Sheet")

DoCmd.Maximize

DoCmd.Close acForm, ("Main Page")

If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project?") = vbYes Then

Call AddNewProject_Click


else
DoCmd.Close acForm ("Project Log Sheet")
DoCmd. OpenForm, ("Main Page")
DoCmd.Maximize

End If

End Sub
 
First, since you are closing and reopening, you should instead use the forms visibility properties. You'll find this makes your database run faster through the code.

Second, you're probably messing up the naming of the function. Either the name you're calling doesn't exist, or it's private in some other module. So make sure you "AddNewProject_Click" function is public and spelled the same.

Did you try it with the underscores?Add_New_Project_Click

Code:
Public Sub Add_new_request_Click()

    DoCmd.OpenForm ("Project Log Sheet")
    DoCmd.Maximize
    Forms("Main Page").Visible = False

    If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project?") = vbYes Then
        AddNewProject_Click
    Else
        Forms("Project Log Sheet").Visible = False
        Forms("Main Page").Visible = True
        DoCmd.Maximize
    End If
End Sub

If AddNewProject is part of a different form, you may have to reference that form.
Code:
Form_FormName.AddNewProject_Click
 
Thanks for this

Was still having problems but not to worry as I have now changed the way my database works so this function is not needed.

Thank you for your help anyway.

Keith ;)
 

Users who are viewing this thread

Back
Top Bottom