If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
View Records for Editing Only
The error trap goes in the sub in the form that does the call, not the form
being called. "PHisaw" wrote: Okay, here's what I have under each. Private Sub JobNumber_Click() (This is on the subform from Switchboard main form.) If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) (This is under form "fWorkLogReminder" that opens under JobNumer above.) If Me.RecordsetClone.RecordCount 1 Then Cancel = True End If Error Handler: If Err.Number = 2501 Then Resume Next End If End Sub It seems if I open with JobNumber and then cancel from the Form_Open event, it errors and highlights DoCmd.OpenForm under job number. Thanks for your continued help!! Pam "Klatuu" wrote: Maybe not. It should be under: Private Sub Form_Open() Open the Properties Dialog for the form. Select the Events tab. Click on the Open event. Click on the small command button with the dots ... Select Code Builder This is where the code goes. "PHisaw" wrote: Klatuu, I put in code for the error, but still get the message and it highlights the line of code to open the form under JobNumber_Click (DoCmd.OpenForm "fWorkLogReminder"): Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub I'm opening "fWorkLogReminder" with the code under JobNumber_Click and cancelling if no records under form "fWorkLogReminder"_Open. Am I doing this right? Do I have the code in the right places? Pam "Klatuu" wrote: Wait, I just thought of something. I know that if you open a report with no records and use the NoData event to close the form, it will throw a 2501 error. Even though you have canceled the report, it still throws the error and you have to trap for it in the calling routine. I would step through the code in debug mode and see if this is what is happening. Here is how I trap for it in a report: PrintReport_Error: If Err.Number 2501 Then MsgBox "Error " & Err.Number & " (" & Err.Description & _ ") in procedure PrintReport of VBA Document Form_frmUPOReports" End If GoTo PrintReport_Exit End Sub "PHisaw" wrote: Klatuu, Thank's so much for picking up post. Your answers are most helpful. I had something similar set up with Recordcount = 0 with cancelling open. I set it to what you have listed and when I click the job number, even when I know there are records, I get the message "The Open Form action was cancelled." I think I have two different events conflicting each other and am not sure how to bring them together. I don't really need the message "no records" I just need for it to open to the record with StopTime blank so tech can close out before opening another job. I have listed code for each. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 1 Then Cancel = True End If End Sub Again, thanks for your help. Pam "Klatuu" wrote: Use the Form's Open event. Test to see if there are any records in the form's recordset. If there are none, present a message box and cancel the open. Canceling the open actually closes the form: Private Sub Form_Open() If Me.Recordset.Recordcount 1 Then Cancel = True MsgBox "No Records For this Form" End If End Sub "PHisaw" wrote: Thanks for replying. Would you mind explaining in detail or code how you did this? You lost me with "write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method ". Thanks, Pam " wrote: hi .. I have done a similar solution for a client and I suggest you write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method and if no records are found then I would msgbox the user telling them so, otherwise have the form pop up. PHisaw wrote: Hi, I have been working on a filter problem and the post I was working from hasn't received any replies and as I've worked out some of the problems, I thought I would repost with the one left that is causing the most difficulty. I have a main form, with subform. The subform has a field "JobNumber" that when clicked will open a form "fWorkLogReminder" with null values in "StopTime" for specific field "Tech" from combo on main form. All works great - except - when no records match (Tech has no empty StopTimes) and the form still opens with a blank entry screen that says 1 of 1. Can't add to it (don't want to) - it just shows blank form. I don't want the user to have this annoyance of blank screen to close. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder", , , , acFormEdit Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub The query for fWorkLogReminder references the Tech from the main form in the criteria grid. I have worked on this for quite some time and have found no solution. If anyone can help, it will be greatly appreciated!! Thanks, Pam |
#12
|
|||
|
|||
View Records for Editing Only
Like this??
Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Error Handler: If Err.Number = 2501 Then Resume Next DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End If End Sub Still getting error msg. Pam "Klatuu" wrote: The error trap goes in the sub in the form that does the call, not the form being called. "PHisaw" wrote: Okay, here's what I have under each. Private Sub JobNumber_Click() (This is on the subform from Switchboard main form.) If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) (This is under form "fWorkLogReminder" that opens under JobNumer above.) If Me.RecordsetClone.RecordCount 1 Then Cancel = True End If Error Handler: If Err.Number = 2501 Then Resume Next End If End Sub It seems if I open with JobNumber and then cancel from the Form_Open event, it errors and highlights DoCmd.OpenForm under job number. Thanks for your continued help!! Pam "Klatuu" wrote: Maybe not. It should be under: Private Sub Form_Open() Open the Properties Dialog for the form. Select the Events tab. Click on the Open event. Click on the small command button with the dots ... Select Code Builder This is where the code goes. "PHisaw" wrote: Klatuu, I put in code for the error, but still get the message and it highlights the line of code to open the form under JobNumber_Click (DoCmd.OpenForm "fWorkLogReminder"): Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub I'm opening "fWorkLogReminder" with the code under JobNumber_Click and cancelling if no records under form "fWorkLogReminder"_Open. Am I doing this right? Do I have the code in the right places? Pam "Klatuu" wrote: Wait, I just thought of something. I know that if you open a report with no records and use the NoData event to close the form, it will throw a 2501 error. Even though you have canceled the report, it still throws the error and you have to trap for it in the calling routine. I would step through the code in debug mode and see if this is what is happening. Here is how I trap for it in a report: PrintReport_Error: If Err.Number 2501 Then MsgBox "Error " & Err.Number & " (" & Err.Description & _ ") in procedure PrintReport of VBA Document Form_frmUPOReports" End If GoTo PrintReport_Exit End Sub "PHisaw" wrote: Klatuu, Thank's so much for picking up post. Your answers are most helpful. I had something similar set up with Recordcount = 0 with cancelling open. I set it to what you have listed and when I click the job number, even when I know there are records, I get the message "The Open Form action was cancelled." I think I have two different events conflicting each other and am not sure how to bring them together. I don't really need the message "no records" I just need for it to open to the record with StopTime blank so tech can close out before opening another job. I have listed code for each. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 1 Then Cancel = True End If End Sub Again, thanks for your help. Pam "Klatuu" wrote: Use the Form's Open event. Test to see if there are any records in the form's recordset. If there are none, present a message box and cancel the open. Canceling the open actually closes the form: Private Sub Form_Open() If Me.Recordset.Recordcount 1 Then Cancel = True MsgBox "No Records For this Form" End If End Sub "PHisaw" wrote: Thanks for replying. Would you mind explaining in detail or code how you did this? You lost me with "write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method ". Thanks, Pam " wrote: hi .. I have done a similar solution for a client and I suggest you write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method and if no records are found then I would msgbox the user telling them so, otherwise have the form pop up. PHisaw wrote: Hi, I have been working on a filter problem and the post I was working from hasn't received any replies and as I've worked out some of the problems, I thought I would repost with the one left that is causing the most difficulty. I have a main form, with subform. The subform has a field "JobNumber" that when clicked will open a form "fWorkLogReminder" with null values in "StopTime" for specific field "Tech" from combo on main form. All works great - except - when no records match (Tech has no empty StopTimes) and the form still opens with a blank entry screen that says 1 of 1. Can't add to it (don't want to) - it just shows blank form. I don't want the user to have this annoyance of blank screen to close. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder", , , , acFormEdit Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub The query for fWorkLogReminder references the Tech from the main form in the criteria grid. I have worked on this for quite some time and have found no solution. If anyone can help, it will be greatly appreciated!! Thanks, Pam |
#13
|
|||
|
|||
View Records for Editing Only
Very Close. I would do it like this:
Private Sub JobNumber_Click() On Error GoTo JobNumber_Click_Error If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" End If JobNumber_Click_Exit: Exit Sub JobNumber_Click_Error: If Err.Number = 2501 Then DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber Else MsgBox "Error " & err.Number & " - " & err.Description End If Goto JobNumber_Click_Exit End Sub "PHisaw" wrote: Like this?? Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Error Handler: If Err.Number = 2501 Then Resume Next DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End If End Sub Still getting error msg. Pam "Klatuu" wrote: The error trap goes in the sub in the form that does the call, not the form being called. "PHisaw" wrote: Okay, here's what I have under each. Private Sub JobNumber_Click() (This is on the subform from Switchboard main form.) If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) (This is under form "fWorkLogReminder" that opens under JobNumer above.) If Me.RecordsetClone.RecordCount 1 Then Cancel = True End If Error Handler: If Err.Number = 2501 Then Resume Next End If End Sub It seems if I open with JobNumber and then cancel from the Form_Open event, it errors and highlights DoCmd.OpenForm under job number. Thanks for your continued help!! Pam "Klatuu" wrote: Maybe not. It should be under: Private Sub Form_Open() Open the Properties Dialog for the form. Select the Events tab. Click on the Open event. Click on the small command button with the dots ... Select Code Builder This is where the code goes. "PHisaw" wrote: Klatuu, I put in code for the error, but still get the message and it highlights the line of code to open the form under JobNumber_Click (DoCmd.OpenForm "fWorkLogReminder"): Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub I'm opening "fWorkLogReminder" with the code under JobNumber_Click and cancelling if no records under form "fWorkLogReminder"_Open. Am I doing this right? Do I have the code in the right places? Pam "Klatuu" wrote: Wait, I just thought of something. I know that if you open a report with no records and use the NoData event to close the form, it will throw a 2501 error. Even though you have canceled the report, it still throws the error and you have to trap for it in the calling routine. I would step through the code in debug mode and see if this is what is happening. Here is how I trap for it in a report: PrintReport_Error: If Err.Number 2501 Then MsgBox "Error " & Err.Number & " (" & Err.Description & _ ") in procedure PrintReport of VBA Document Form_frmUPOReports" End If GoTo PrintReport_Exit End Sub "PHisaw" wrote: Klatuu, Thank's so much for picking up post. Your answers are most helpful. I had something similar set up with Recordcount = 0 with cancelling open. I set it to what you have listed and when I click the job number, even when I know there are records, I get the message "The Open Form action was cancelled." I think I have two different events conflicting each other and am not sure how to bring them together. I don't really need the message "no records" I just need for it to open to the record with StopTime blank so tech can close out before opening another job. I have listed code for each. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 1 Then Cancel = True End If End Sub Again, thanks for your help. Pam "Klatuu" wrote: Use the Form's Open event. Test to see if there are any records in the form's recordset. If there are none, present a message box and cancel the open. Canceling the open actually closes the form: Private Sub Form_Open() If Me.Recordset.Recordcount 1 Then Cancel = True MsgBox "No Records For this Form" End If End Sub "PHisaw" wrote: Thanks for replying. Would you mind explaining in detail or code how you did this? You lost me with "write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method ". Thanks, Pam " wrote: hi .. I have done a similar solution for a client and I suggest you write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method and if no records are found then I would msgbox the user telling them so, otherwise have the form pop up. PHisaw wrote: Hi, I have been working on a filter problem and the post I was working from hasn't received any replies and as I've worked out some of the problems, I thought I would repost with the one left that is causing the most difficulty. I have a main form, with subform. The subform has a field "JobNumber" that when clicked will open a form "fWorkLogReminder" with null values in "StopTime" for specific field "Tech" from combo on main form. All works great - except - when no records match (Tech has no empty StopTimes) and the form still opens with a blank entry screen that says 1 of 1. Can't add to it (don't want to) - it just shows blank form. I don't want the user to have this annoyance of blank screen to close. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder", , , , acFormEdit Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub The query for fWorkLogReminder references the Tech from the main form in the criteria grid. I have worked on this for quite some time and have found no solution. If anyone can help, it will be greatly appreciated!! Thanks, Pam |
#14
|
|||
|
|||
View Records for Editing Only
Klatuu,
IT WORKS!!!!! Thank you so much for hanging in there with me to get it to work! I have spent a considerable amount of time rearranging code trying to make this work. I think I need to research error handling. Again, thank you - greatly appreciated!! Pam "Klatuu" wrote: Very Close. I would do it like this: Private Sub JobNumber_Click() On Error GoTo JobNumber_Click_Error If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" End If JobNumber_Click_Exit: Exit Sub JobNumber_Click_Error: If Err.Number = 2501 Then DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber Else MsgBox "Error " & err.Number & " - " & err.Description End If Goto JobNumber_Click_Exit End Sub "PHisaw" wrote: Like this?? Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Error Handler: If Err.Number = 2501 Then Resume Next DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End If End Sub Still getting error msg. Pam "Klatuu" wrote: The error trap goes in the sub in the form that does the call, not the form being called. "PHisaw" wrote: Okay, here's what I have under each. Private Sub JobNumber_Click() (This is on the subform from Switchboard main form.) If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) (This is under form "fWorkLogReminder" that opens under JobNumer above.) If Me.RecordsetClone.RecordCount 1 Then Cancel = True End If Error Handler: If Err.Number = 2501 Then Resume Next End If End Sub It seems if I open with JobNumber and then cancel from the Form_Open event, it errors and highlights DoCmd.OpenForm under job number. Thanks for your continued help!! Pam "Klatuu" wrote: Maybe not. It should be under: Private Sub Form_Open() Open the Properties Dialog for the form. Select the Events tab. Click on the Open event. Click on the small command button with the dots ... Select Code Builder This is where the code goes. "PHisaw" wrote: Klatuu, I put in code for the error, but still get the message and it highlights the line of code to open the form under JobNumber_Click (DoCmd.OpenForm "fWorkLogReminder"): Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub I'm opening "fWorkLogReminder" with the code under JobNumber_Click and cancelling if no records under form "fWorkLogReminder"_Open. Am I doing this right? Do I have the code in the right places? Pam "Klatuu" wrote: Wait, I just thought of something. I know that if you open a report with no records and use the NoData event to close the form, it will throw a 2501 error. Even though you have canceled the report, it still throws the error and you have to trap for it in the calling routine. I would step through the code in debug mode and see if this is what is happening. Here is how I trap for it in a report: PrintReport_Error: If Err.Number 2501 Then MsgBox "Error " & Err.Number & " (" & Err.Description & _ ") in procedure PrintReport of VBA Document Form_frmUPOReports" End If GoTo PrintReport_Exit End Sub "PHisaw" wrote: Klatuu, Thank's so much for picking up post. Your answers are most helpful. I had something similar set up with Recordcount = 0 with cancelling open. I set it to what you have listed and when I click the job number, even when I know there are records, I get the message "The Open Form action was cancelled." I think I have two different events conflicting each other and am not sure how to bring them together. I don't really need the message "no records" I just need for it to open to the record with StopTime blank so tech can close out before opening another job. I have listed code for each. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 1 Then Cancel = True End If End Sub Again, thanks for your help. Pam "Klatuu" wrote: Use the Form's Open event. Test to see if there are any records in the form's recordset. If there are none, present a message box and cancel the open. Canceling the open actually closes the form: Private Sub Form_Open() If Me.Recordset.Recordcount 1 Then Cancel = True MsgBox "No Records For this Form" End If End Sub "PHisaw" wrote: Thanks for replying. Would you mind explaining in detail or code how you did this? You lost me with "write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method ". Thanks, Pam " wrote: hi .. I have done a similar solution for a client and I suggest you write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method and if no records are found then I would msgbox the user telling them so, otherwise have the form pop up. PHisaw wrote: Hi, I have been working on a filter problem and the post I was working from hasn't received any replies and as I've worked out some of the problems, I thought I would repost with the one left that is causing the most difficulty. I have a main form, with subform. The subform has a field "JobNumber" that when clicked will open a form "fWorkLogReminder" with null values in "StopTime" for specific field "Tech" from combo on main form. All works great - except - when no records match (Tech has no empty StopTimes) and the form still opens with a blank entry screen that says 1 of 1. Can't add to it (don't want to) - it just shows blank form. I don't want the user to have this annoyance of blank screen to close. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder", , , , acFormEdit Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub The query for fWorkLogReminder references the Tech from the main form in the criteria grid. I have worked on this for quite some time and have found no solution. If anyone can help, it will be greatly appreciated!! Thanks, Pam |
#15
|
|||
|
|||
View Records for Editing Only
Glad I could help, Pam.
Error handling is not really that mysterious. Do some reading in Help. almost all the subs and functions in my apps have an error handling routine. In fact, I have it set so the error message tells me what module and when procedure the error occurred in. It makes it much easier to chase a bug. "PHisaw" wrote: Klatuu, IT WORKS!!!!! Thank you so much for hanging in there with me to get it to work! I have spent a considerable amount of time rearranging code trying to make this work. I think I need to research error handling. Again, thank you - greatly appreciated!! Pam "Klatuu" wrote: Very Close. I would do it like this: Private Sub JobNumber_Click() On Error GoTo JobNumber_Click_Error If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" End If JobNumber_Click_Exit: Exit Sub JobNumber_Click_Error: If Err.Number = 2501 Then DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber Else MsgBox "Error " & err.Number & " - " & err.Description End If Goto JobNumber_Click_Exit End Sub "PHisaw" wrote: Like this?? Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Error Handler: If Err.Number = 2501 Then Resume Next DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End If End Sub Still getting error msg. Pam "Klatuu" wrote: The error trap goes in the sub in the form that does the call, not the form being called. "PHisaw" wrote: Okay, here's what I have under each. Private Sub JobNumber_Click() (This is on the subform from Switchboard main form.) If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) (This is under form "fWorkLogReminder" that opens under JobNumer above.) If Me.RecordsetClone.RecordCount 1 Then Cancel = True End If Error Handler: If Err.Number = 2501 Then Resume Next End If End Sub It seems if I open with JobNumber and then cancel from the Form_Open event, it errors and highlights DoCmd.OpenForm under job number. Thanks for your continued help!! Pam "Klatuu" wrote: Maybe not. It should be under: Private Sub Form_Open() Open the Properties Dialog for the form. Select the Events tab. Click on the Open event. Click on the small command button with the dots ... Select Code Builder This is where the code goes. "PHisaw" wrote: Klatuu, I put in code for the error, but still get the message and it highlights the line of code to open the form under JobNumber_Click (DoCmd.OpenForm "fWorkLogReminder"): Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub I'm opening "fWorkLogReminder" with the code under JobNumber_Click and cancelling if no records under form "fWorkLogReminder"_Open. Am I doing this right? Do I have the code in the right places? Pam "Klatuu" wrote: Wait, I just thought of something. I know that if you open a report with no records and use the NoData event to close the form, it will throw a 2501 error. Even though you have canceled the report, it still throws the error and you have to trap for it in the calling routine. I would step through the code in debug mode and see if this is what is happening. Here is how I trap for it in a report: PrintReport_Error: If Err.Number 2501 Then MsgBox "Error " & Err.Number & " (" & Err.Description & _ ") in procedure PrintReport of VBA Document Form_frmUPOReports" End If GoTo PrintReport_Exit End Sub "PHisaw" wrote: Klatuu, Thank's so much for picking up post. Your answers are most helpful. I had something similar set up with Recordcount = 0 with cancelling open. I set it to what you have listed and when I click the job number, even when I know there are records, I get the message "The Open Form action was cancelled." I think I have two different events conflicting each other and am not sure how to bring them together. I don't really need the message "no records" I just need for it to open to the record with StopTime blank so tech can close out before opening another job. I have listed code for each. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder" Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 1 Then Cancel = True End If End Sub Again, thanks for your help. Pam "Klatuu" wrote: Use the Form's Open event. Test to see if there are any records in the form's recordset. If there are none, present a message box and cancel the open. Canceling the open actually closes the form: Private Sub Form_Open() If Me.Recordset.Recordcount 1 Then Cancel = True MsgBox "No Records For this Form" End If End Sub "PHisaw" wrote: Thanks for replying. Would you mind explaining in detail or code how you did this? You lost me with "write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method ". Thanks, Pam " wrote: hi .. I have done a similar solution for a client and I suggest you write a function which queries the table you are looking up for open issues and return a number which should represent a outstanding/open issues. You then will attach the function to the clicked method and if no records are found then I would msgbox the user telling them so, otherwise have the form pop up. PHisaw wrote: Hi, I have been working on a filter problem and the post I was working from hasn't received any replies and as I've worked out some of the problems, I thought I would repost with the one left that is causing the most difficulty. I have a main form, with subform. The subform has a field "JobNumber" that when clicked will open a form "fWorkLogReminder" with null values in "StopTime" for specific field "Tech" from combo on main form. All works great - except - when no records match (Tech has no empty StopTimes) and the form still opens with a blank entry screen that says 1 of 1. Can't add to it (don't want to) - it just shows blank form. I don't want the user to have this annoyance of blank screen to close. Private Sub JobNumber_Click() If IsNull(Forms!fWorkLog!StopTime) Then DoCmd.OpenForm "fWorkLogReminder", , , , acFormEdit Else DoCmd.OpenForm "fGeneralInfo", , , "JobNumber=" & Me!JobNumber End If End Sub The query for fWorkLogReminder references the Tech from the main form in the criteria grid. I have worked on this for quite some time and have found no solution. If anyone can help, it will be greatly appreciated!! Thanks, Pam |
|
Thread Tools | |
Display Modes | |
|
|