Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35

    I'm COMPLETLY STUMPED

    If Not (Forms!frmInputPara.txtName = "" Or Forms!frmInputPara.txtParagraph = "") Then
    ...Code
    Else
    If (Forms!frmInputPara.txtName = "" Or Forms!frmInputPara.txtParagraph = "") Then
    MsgBox "WINGO!"
    Else
    MsgBox "O NO!"
    End If
    End If



    This makes 0 sense at all. I should never get the error message "O NO!"
    there is no syntax error, with both fields blank, or either one field blank, I get "O NO!" instead of the intended "WINGO!"

    Can someone please explain what I'm doing wrong here??

    Additional stuff:
    I have Debugged with txtName blank. It confirms the first statment as True (so it goes to the Else because of the Not)

    then goes to the second If, which is within the Else, WHICH IS THE EXACT SAME (copy paste) without the Not, and for some reason skips over it, into the else containing "O NO!"

    just does not make sense.

    Help plz T.T

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    My guess is that the controls are Null. Try this type of test:

    If Len(Me.SomeControl & vbNullString) = 0 Then

    which tests for both Null and the ZLS.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Why the second If? An if statement says if true do this else do that. Your statement says if true do this else if false do this else do that. You only have 2 values true and false Why put in the second if? Secondly prior to the first if statement put in the following

    msgbox forms!frminputpara.txtname = "",vbokonly,"Test1"
    msgbox forms!frminputpara.txtparagraph="",vbokonly,"Test2 "

    This will show the true (-1) False (0) Value for both of your parameters. Make a chart with 3 columns run through your routine and put the appropriate value in each column test1, test2, result. See what's actually going on Post your results back here if you're still having issues.



    If Not (Forms!frmInputPara.txtName = "" Or Forms!frmInputPara.txtParagraph = "") Then
    ...Code
    Else
    MsgBox "WINGO!"
    End If

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    pbaldy-you posted while I was typing yours makes more sense. I hadn't thought of nulls.

  5. #5
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    to pbaldy:

    I have an issue with focus, where I can not focus two items at once,

    Also if that were the case wouldn't the first if statment get passed as True because of the Not, or give a null pointer exeption of some kind?

    I do appretiate the help tho

    To Ray:
    I formatted it like that to simplify things and try to get it to work. my actual code looks like this:

    Private Sub Command8_Click()
    If Not (Forms!frmInputPara.txtName = "" Or Forms!frmInputPara.txtParagraph = "") Then

    ...Code

    Else
    'Displays the error msg depending on what the user has missed
    Dim errorMsg As String
    errorMsg = "Please make the following change(s): "

    If (Forms!frmInputPara.txtName = "" And Forms!frmInputPara.txtParagraph = "")Then
    errorMsg = errorMsg & "Add a name and a paragraph."
    MsgBox "WINGO!"
    ElseIf (Forms!frmInputPara.txtParagraph = "") Then
    errorMsg = errorMsg & "Add a paragraph."
    Else
    errorMsg = errorMsg & "Add a name."
    MsgBox "O NO!"
    End If
    MsgBox errorMsg
    End If
    End Sub


    Edit: I have confirmed that the values are Null, (got Null error using Ray's test1, test2)
    I believe there was also an issue where as I was not saving the actual Text inside of the controls.

    My code is now working as intended, thanks in part, both of you!~
    Last edited by allstar45; 03-05-2012 at 02:32 PM. Reason: additional Facts

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't understand the issue with focus. How does that relate to this? I take it you didn't even try the recommended change? Do these results from the Immediate window give you pause?

    ?1=1
    True
    ?not 1=1
    False
    ?null = ""
    Null
    ?not null = ""
    Null
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Glad you got it working.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Also glad you got it working. What does the code look like now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    Private Sub Command8_Click()
    Dim para As Variant
    Dim name As Variant

    Forms!frminputpara.txtName.SetFocus
    name = Forms!frminputpara.txtName.Text
    Forms!frminputpara.txtParagraph.SetFocus
    para = Forms!frminputpara.txtParagraph.Text

    If Not (name = "" Or para = "") Then

    ' DoCmd.OpenQuery ("qryInputPara")
    Forms!frminputpara.txtName.SetFocus
    MsgBox Forms!frminputpara.txtName.Text + " Has been added as a Paragraph."

    'resets the form after it's been inserted into tables.
    Forms!frminputpara.txtName.SetFocus
    Forms!frminputpara.txtName.Text = ""

    Forms!frminputpara.CheckBAEQ.SetFocus
    Forms!frminputpara.CheckBAEQ = No

    Forms!frminputpara.CheckPAEQ.SetFocus
    Forms!frminputpara.CheckPAEQ = No

    Forms!frminputpara.CheckIAEQ.SetFocus
    Forms!frminputpara.CheckIAEQ = No

    Forms!frminputpara.CheckAEFQ.SetFocus
    Forms!frminputpara.CheckAEFQ = No

    Forms!frminputpara.CheckPAEQ2.SetFocus
    Forms!frminputpara.CheckPAEQ2 = No

    Forms!frminputpara.CheckIAEQ2.SetFocus
    Forms!frminputpara.CheckIAEQ2 = No

    Else
    'Displays the error msg depending on what the user has missed
    Dim errorMsg As String
    errorMsg = "Please make the following change(s): "

    If (name = "" And para = "") Then
    errorMsg = errorMsg & "Add a name and Add the paragraph."
    ElseIf Len(para & vbNullString) = 0 Then
    errorMsg = errorMsg & "Add the paragraph."
    Else
    errorMsg = errorMsg & "Add a name."
    End If

    MsgBox errorMsg
    End If
    End Sub


    ------
    That is my code as it stands, as you can see I did implement your method, and it worked,

    I had two issues before:

    1) when I was checking two controls at once it gave me an error saying "Can not access control when not focused" or something similar to that.

    2) The other issue was that I was compairing
    Me.txtName and Me.txtParagraph to ""
    and not
    Me.txtName.Text to ""


    I solved these issues by assigning Me.txtName.Text to Varient name and Me.txtParagraph.Text to para.
    This solved the focusing issue because I could focus, assign then re-focus to a different control then assign.

    Hope that makes sense :/ explination has never been my strong suit

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your problem with focus was due to using the .Text property, which requires it. If you used the default .Value property, you would not need to set focus. You shouldn't need any of those SetFocus lines.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    does the same go for Checkbox.Value (true false) and non-visable text?

    And what about combo boxes? is there a work around for not focusing them?

    This really solves a lot of my problems instead of having to have a bunch of additional work arounds!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You shouldn't need to set focus to any of them. Just use .Value instead of .Text. You only need .Text if you need each keystroke. Here's some info my friend Jason put together:

    http://www.baldyweb.com/ValueText.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    So does this also work in Queries?

    Do you know any workarounds for Combo boxes aswell (so I dont have to focus it)?

    The only way I have been able to have a combo selection in a querie has been assigning a label to the value I want on the form, because when I try to run something like:
    Forms!frmInputPara.Combo5.Column(0) in my querie, it gives me a run-time error 3085
    (Undefined function 'Forms!frmInputPara.Combo5.Column' in expresstion)
    with the DoCmd.OpenQuery line highlighted.

    Can I use .Value somehow to get the value of a combobox.column value?

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Using the Column property is an issue in queries. If the desired column is the bound column (which it typically would be), you can simply have this in the query:

    Forms!frmInputPara.Combo5

    If it's not the bound column, I think you might be able to wrap the form reference in the Eval() function, but don't quote me on that without testing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    allstar45 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    35
    Thanks, the desired column WAS the bound column, works even better now

    Cheers~

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Stumped: Query asking for info twice?
    By Heatshiver in forum Programming
    Replies: 2
    Last Post: 01-09-2012, 10:14 AM
  2. Stumped on date
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 12-29-2011, 02:45 PM
  3. Really stumped newbie here
    By alwittlich in forum Access
    Replies: 5
    Last Post: 05-18-2011, 11:55 AM
  4. Stumped on an INSERT
    By Elisa in forum Programming
    Replies: 1
    Last Post: 12-26-2009, 10:49 AM
  5. Completly lost...
    By fairytalesrcute in forum Access
    Replies: 1
    Last Post: 05-14-2009, 09:24 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