Results 1 to 14 of 14
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hidden Form (A2k SR1)

    These four lines of code are producing errors in the below full code:-
    ************************************************** **************************
    Forms!mnuworkshopmanager.Visible = True
    Forms!mnuworkshopmanager.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.Dropdown
    ************************************************** **************************
    The form in question is not closed but hidden behind the main form which this snippet is from.
    Can any-one see why the full code can not find the form mnuWorkShopManager when I know its behind there sopme where.
    It may be a couple of forms behind but I wouldn't have thought it would cause a problem. ???

    Private Sub Form_Unload(Cancel As Integer)
    If Me.Status = "I" Then
    Forms!frmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    strMsgPrompt = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle = "!!"
    intButType = vbOKOnly + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbOKOnly Then
    End If
    End If

    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Exit This Form Until A Client Has Been Entered!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    End If

    Forms!mnuworkshopmanager.Visible = True
    Forms!mnuworkshopmanager.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.Dropdown
    Exit Sub

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Do you get an error on the first of the four lines? And what is the exact error message?

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    Hans I'm getting all kinds of things happening, I'm working on it now. Let me explain, I've been swapping the code around:

    The first section fails, the msgbox pops up warning the user he cannot exit and then exits with cmbClientCode still Null, setting focus on the mnuWorkShopManager ?? Do I need to move my End If's ??

    The second section, if status ="I" works ok, and exits correctly finding mnuWorkShopManager.

    Private Sub Form_Unload(Cancel As Integer)
    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Exit This Form Until A Client Has Been Entered!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    End If

    If Me.Status = "I" Then
    Forms!frmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    strMsgPrompt = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle = "!!"
    intButType = vbOKOnly + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbOKOnly Then
    End If
    End If

    Forms!mnuworkshopmanager.Visible = True
    Forms!mnuworkshopmanager.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.Dropdown
    Exit Sub
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Hi Dave,

    I would start by putting an Exit Sub instruction before the first End If. You don't want the rest of your code to execute if cmbClientCode is still empty.

    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Exit This Form Until A Client Has Been Entered!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    Exit Sub
    End If

    (and, by the way, the Exit Sub immediately above End Sub is superfluous).

    If you still have problems after this, post back (with a description of what happens then).

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    This seems to be working.
    Funny how the simplest things can throw the spanner in the works.
    You're just a wealth of knowledge. Thanks, Dave

    Private Sub Form_Unload(Cancel As Integer)
    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Exit This Form Until A Client Has Been Entered!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    Exit Sub
    End If
    If Me.Status = "I" Then
    Forms!frmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    strMsgPrompt = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle = "!!"
    intButType = vbOKOnly + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbOKOnly Then
    End If
    End If
    Forms!mnuworkshopmanager.Visible = True
    Forms!mnuworkshopmanager.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.Dropdown
    End Sub

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    Hans, I use this code on keyDown VbKeyF3 and am having a similar problem to the above.
    I added the If Me.Status = "I" Then Forms!frmDetails!Status = "F" etc, section and now the {F3} doesn't call the code.
    Can you see any errors in the below.
    I can't see where I'm going wrong.
    Regards
    Dave





    Private Sub Command296_Click()
    On Error GoTo errtrap
    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Create A New Estimate Until A Client Has Been Entered For The Current Record!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    Exit Sub
    End If
    If Me.Status = "I" Then
    Forms!frmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    Dim intButSelected1 As Integer, intButType1 As Integer
    Dim strMsgPrompt1 As String, strMsgTitle1 As String
    strMsgPrompt1 = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle1 = "!!"
    intButType1 = vbOKOnly + vbDefaultButton1
    intButSelected1 = MsgBox(strMsgPrompt1, intButType1, strMsgTitle1)
    If intButSelected1 = vbOKOnly Then
    Cancel = True
    Me.DummyEst.SetFocus
    Exit Sub
    End If

    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    Dim stDocName As String
    Dim stLinkCriteria As String
    Me.DummyEst.SetFocus
    Me.cmbSearch.Visible = False
    Me.cmbSearchSub.Visible = False
    Forms!frmDetails.Requery
    strMsgPrompt = "Create New Estimate"
    strMsgTitle = "!!"
    intButType = vbYesNo + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbYes Then
    stDocName = "frmOption"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms!frmDetails.SetFocus
    DoCmd.GoToRecord , , acNewRec
    Forms!frmDetails!EstimateNo = DMax("estimateno", "Tbldetails") + 1
    Forms!frmDetails!DummyEst.SetFocus
    DoCmd.Close acForm, "frmCreateEstimate", acSaveYes
    Forms!frmDetails!DummyEst.SetFocus
    Forms!frmDetails!Supp = 0
    Forms!frmDetails.Requery
    Else
    Forms!frmDetails.SetFocus
    Forms!frmDetails!DummyEst.SetFocus
    Forms!frmDetails.Requery
    DoCmd.Close acForm, "frmCreateEstimate", acSaveYes
    Forms!frmDetails.Requery
    End If
    End If

    Exit Sub
    errtrap:
    End Sub

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Dave,

    Here are my comments. I will place a modified version of your code at the end of this reply.
    <UL><LI>Event procedures such as Form_Unload and <control>_BeforeUpdate have an argument Cancel that you can set to True if you want to cancel the Unload or Update. But <control>_Click has no arguments, so setting Cancel = True won't have any effect. (If you have Option Explicit at the top of the module, you will get a syntax error, because Cancel is not defined in the context of a Click event handler.)
    <LI>There is no point in declaring separate sets of variables for each message box; you can declare one set and re-use it.
    <LI>The variable stLinkCriteria is never used.
    <LI>There is no point in checking the return value of a message box if it has an OK button only.
    <LI>You set focus to a control several times, then requery the form. You must put the focus to the desired control after requerying.
    <LI>You use acSaveYes when closing a form. This means that you save the design of the form, not the record. In a multi-user environment, this is very dangerous. I would either omit this argument, or use acSaveNo.
    <LI>If Status is not "I", nothing happens. I haven't changed that, but I suspect that the End If belonging to If Status = "I" Then should be placed after showing the message box that Status has been set to "F", instead of near the end of the procedure.
    <LI>A lot of instructions were repeated, I suppose because the code was assembled from bits and pieces. I have tried to streamline this. Please check whether it does what you want.
    <LI>Please rename your command button to something meaningful. You may know what Command296 is now, but if you have to update your code later on, names like that make life more difficult.[/list]This is the modified code:

    Private Sub Command296_Click()
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    Dim stDocName As String
    On Error GoTo errtrap

    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Create A New Estimate Until A Client Has Been Entered For The Current Record!! "
    Me.cmbClientCode.SetFocus
    Exit Sub
    End If

    If Me.Status = "I" Then
    Forms!frmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    strMsgPrompt = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle = "!!"
    intButType = vbOKOnly + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    ' *******
    Me.cmbSearch.Visible = False
    Me.cmbSearchSub.Visible = False
    strMsgPrompt = "Create New Estimate"
    strMsgTitle = "!!"
    intButType = vbYesNo + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbYes Then
    stDocName = "frmOption"
    DoCmd.OpenForm stDocName
    DoCmd.GoToRecord , , acNewRec
    Forms!frmDetails!EstimateNo = DMax("EstimateNo", "tblDetails") + 1
    End If
    DoCmd.Close acForm, "frmCreateEstimate", acSaveNo
    Forms!frmDetails.SetFocus
    Forms!frmDetails.Requery
    Forms!frmDetails!DummyEst.SetFocus
    End If ' Perhaps this should be moved to *******

    Exit Sub
    errtrap:
    MsgBox Err.Description, vbExclamation
    End Sub

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    Hans, your comments are truly noted.
    I realised the cancel event with the on-click, some-where on my way home last night, ie How can you cancel a click when it has already been clicked !!
    Yes I need to apply the button naming convention at some stage (Which I will,Believe me) when I book myself a couple of weeks off.

    Any way, the problem at hand is still here.
    I've copied your code and played about with the end if's to no avail.
    I've attached a snippet with the important bits and a descriptive series of events.
    I wondered if you would mind checking it out for me.

    Regards
    Dave
    Attached Files Attached Files

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Hi Dave,

    I'm stuck with Access 97 here, so could you save your db in '97 format and attach it? Thanks in advance.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    Here you go
    Attached Files Attached Files

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Dave,

    I'm very sorry. I can open the database and the table now, but I get an error message when I try to open the form. It probably contains features that are new in Access 2000.

    But I'm sure that some other Lounger with Access 2000 or XP will be willing to look at it.

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    I've tried also, I have A97 & 2000.

    Perhaps some-one else could help.

    Thanks any way.
    Regards
    Dave

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hidden Form (A2k SR1)

    Don't ask me how, but I've done it.
    It works, It's tested.
    Many thanks to all. here's the code:

    Private Sub Command296_Click()
    On Error GoTo errtrap
    If IsNull([cmbClientCode]) Then
    MsgBox " You Can Not Create A New Estimate Until A Client Has Been Entered For The Current Record!! "
    Cancel = True
    Me.cmbClientCode.SetFocus
    Exit Sub
    End If
    '################################################# ###################################
    If Me.Status = "I" Then
    Forms!FrmDetails!Status = "F"
    RunCommand acCmdSaveRecord
    Dim intButSelected1 As Integer, intButType1 As Integer
    Dim strMsgPrompt1 As String, strMsgTitle1 As String
    strMsgPrompt1 = "This File Has been Invoiced But Not F'd. This Has Now Been Updated Automatically"
    strMsgTitle1 = "!!"
    intButType1 = vbOKOnly + vbDefaultButton1
    intButSelected1 = MsgBox(strMsgPrompt1, intButType1, strMsgTitle1)
    If intButSelected1 = vbOKOnly Then
    End If
    End If
    '################################################# ###################################
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    Dim stDocName As String
    Dim stLinkCriteria As String
    Me.DummyEst.SetFocus
    Me.cmbSearch.Visible = False
    Me.cmbSearchSub.Visible = False
    Forms!FrmDetails.Requery
    strMsgPrompt = "Create New Estimate"
    strMsgTitle = "!!"
    intButType = vbYesNo + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbYes Then
    stDocName = "frmOption"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms!FrmDetails.SetFocus
    DoCmd.GoToRecord , , acNewRec
    Forms!FrmDetails!EstimateNo = DMax("estimateno", "Tbldetails") + 1
    Forms!FrmDetails!DummyEst.SetFocus
    DoCmd.Close acForm, "frmCreateEstimate"
    Forms!FrmDetails!DummyEst.SetFocus
    Forms!FrmDetails!Supp = 0
    Forms!FrmDetails.Requery
    Else
    Forms!FrmDetails.SetFocus
    Forms!FrmDetails!DummyEst.SetFocus
    Forms!FrmDetails.Requery
    DoCmd.Close acForm, "frmCreateEstimate"
    Forms!FrmDetails.Requery
    End If
    Exit Sub
    errtrap:
    End Sub

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hidden Form (A2k SR1)

    Congratulations!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •