Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OpenArgs problem (2000)

    Hi,
    I have this code:
    Private Sub CmdStart_Click()
    If IsNull(Me.CboAreaID) Then
    MsgBox "No Area has been selected", vbInformation, "Error"
    Exit Sub
    End If

    DoCmd.OpenForm "FrmMain", , , "[AreaID] = " & Me.CboAreaID, , , Me.CboAreaID
    Exit_CmdStart_Click:
    Exit Sub

    Err_CmdStart_Click:
    MsgBox "No Area has been selected", vbExclamation + vbOKOnly, "Please Amend"
    Resume Exit_CmdStart_Click

    End Sub

    What this does is the user selects an Area from CboAreaID in FrmStartUp. Once this is selected, they press CmdStart which then opens FrmMain and filters according to the AreaID. This bit works fine.

    On the Load event of FrmMain i have:

    Private Sub Form_Load()
    Me.CboFindRecord.RowSource = "SELECT [TblMain].[URNID], [TblMain].[DefSurname], " & _
    "[TblMain].[DefForename], [TblMain].[URN], [TblMain].[AreaID] FROM TblMain " & _
    "WHERE [TblMain].[AreaID]=" & Me.OpenArgs
    Me.[AreaID].DefaultValue = Me.OpenArgs

    ....

    In theory this filters according to the selection made in FrmStartUp>CboAreaID
    The problem I'm having is that for every new record added I'd like the AreaID field in FrmMain to be the same as the OpenArg....can't do it thought, although I thought that it had been resolved with Hans on a previous post.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: OpenArgs problem (2000)

    I have found OpenArgs to be somewhat unreliable as a variable. What I usually do is use the Open event of the form to store the OpenArgs value to a module level variable. After that, I refer to the variable instead of OpenArgs itself.
    Charlotte

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

    Re: OpenArgs problem (2000)

    Is AreaID a text field? If so, try

    Me.[AreaID].DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)

  4. #4
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    Nope AreaID is a numerical field......

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

    Re: OpenArgs problem (2000)

    I don't think we'll get further without seeing the database.

  6. #6
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    Though ya might say that!!!

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

    Re: OpenArgs problem (2000)

    I had to wade through a lot of changes before I could do anything with the database, but the default value seems to work OK. Please note that you have TWO invisible text boxes bound to the AreaID field: TxtAreaID in the form header, and AreaID in the detail section. The default value of the latter gets set. I would remove the first one, it only confuses the issue.

  8. #8
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    Thanks Hans, that does the job.
    Could you also advise me on another query I have with this database?
    On FrmMain the user would like to have the ability to add additional defendants and their relevant solicitors but they don't want the layout changed.
    My initial thought was to have a control that On Focus would display a hidden sub form where the user could enter further data.
    Me.FrmSubDefendant.Visible=True
    Currently the sub form is called FrmSubDefendant(based on TblSubDefendant), and is a One to Many relationship to TblMain based on URNID.
    On this sub form I have CmdClose which has the standard coding behind it to close the form but when I attempt to close it, it displays Run-time error '2501', so I'm not too sure whether my approach is correct.

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

    Re: OpenArgs problem (2000)

    You can't close a subform, only a main form. When the user is done with the subform, it can be hidden again. To do so:
    1) Set focus to another control on the main form.
    2) Set the Visible property of the subform as a control on the main form to No.

    Private Sub cmdClose_Click()
    Me.Parent.OtherControl.SetFocus
    Me.Parent.SubformAsControl.Visible = False
    End Sub

  10. #10
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    That makes sense as the subform is actually part of the main form.
    Is there a way that I can check to see if the subform has any data in it that relates to the main form so that I can display a message or different colour on the command button that displays the sub form? Basically so that the user instantly knows there are additional defendants.

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

    Re: OpenArgs problem (2000)

    You can put a text box txtCount on the subform with control source =Count(*). This text box can be hidden (Visible = No).
    You can check from the main form if this text box contains 0:

    If Me.SubFormAsControl!txtCount = 0 Then
    ...
    End If

  12. #12
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    Doesn't seem to work for some reason.............

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

    Re: OpenArgs problem (2000)

    Oh.





    Please provide sufficient information or attach a file.

  14. #14
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs problem (2000)

    TxtCount literally doesn't count. its control source is:
    =Count(*)
    This has been placed on the subform. With:

    If Me.SubFormAsControl!txtCount = 0 Then
    ...
    End If

    Being on the main form.

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

    Re: OpenArgs problem (2000)

    Make txtCount visible for the moment. Does it display the number of subform records?

Page 1 of 2 12 LastLast

Posting Permissions

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