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

    Re: Verify Null of Control (A2K)

    Try

    <code>If IsNull(x) or Len(x & "") = 0 then</code>
    Charlotte

  2. #2
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Verify Null of Control (A2K)

    Edited by HansV to break very long lines between <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags.
    BTW there is no <!t>[/tab]<!/t> tag.


    I have the following code that needs to look for each control name ending in "gl". For each control ending in "gl" the code needs to determine if the control is Null. If the control is Null, the user gets a message informing them they MUST make a selection, the focus is set to that control and the user is taken to that control.

    <pre>Public Function Verify(gl)
    Dim ctl As Control
    Dim Response As Integer

    If Screen.ActiveControl.Value = -1 Then
    v = True
    Else
    v = False
    End If

    For Each x In Screen.ActiveForm.Controls
    If Right(x.Name, 2) = gl Then
    'If IsNull x.Name, Then Having problem here to determine if it's Null
    Response = MsgBox("You must make a selection for ", vbOKOnly)
    'want the name of the NULL CONTROL included in message
    x.Visible = v
    x.SetFocus
    DoCmd.GoToControl x.Name
    'Having trouble here to get the user taken to the offending control

    End If
    Next x
    End Function
    </pre>

    Could someone show me the error of my ways and point me in the right direction?

    Thanks in advance.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: Verify Null of Control (A2K)

    Is gl the literal text, as your description indicates, or a string variable that holds the text to be used, as the function definition implies?

    You declare a variable ctl as Control, but you use an undeclared variable x.
    You also haven't declared v.
    You don't want to check whether the Name of the control is null, but whether its Value is null.
    If you already use SetFocus, there is no need to use GoToControl.

    Assuming that gl is a variable, try this:

    Public Function Verify(gl)
    Dim ctl As Control
    Dim Response As Integer
    Dim v As Boolean
    v = (Screen.ActiveControl.Value = -1)
    For Each ctl In Screen.ActiveForm.Controls
    If Right(ctl.Name, 2) = gl Then
    If IsNull(ctl.Value) Then
    MsgBox "You must make a selection for " & ctl.Name, vbOKOnly
    ctl.Visible = v
    ctl.SetFocus
    Exit Function
    End If
    End If
    Next ctl
    End Function

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Verify Null of Control (A2K)

    It wasn't until the code worked correctly did I realize I overlooked something.

    This is a tabbed form, not that that should matter, but for better understanding.

    The tabbed form has the following TABS:
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: Verify Null of Control (A2K)

    You didn't answer my question. Your use of gl and rt makes no sense - they are literal strings, but you use them as the names of variables. Change the function as follows.

    Public Function VerifyIt()
    Dim ctl As Control
    For Each ctl In Screen.ActiveForm.Controls
    If Right(ctl.Name, 2) = "gl" Or Right(ctl.Name, 2) = "rt" Then
    If IsNull(ctl.Value) Then
    MsgBox "You must make a selection for " & ctl.Name
    ctl.Visible = True
    ctl.SetFocus
    Exit Function
    End If
    End If
    Next ctl
    End Function

    and call it from the AfterUpdate event of chkVerified simply as VerifyIt instead of VeriffyIt(gl, rt)

  6. #6
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Verify Null of Control (A2K)

    Sorry I didn't answer the question....I'm using the gl and rt as extensions of the control names. My thought was I needed a way for "FOR each" peice of code to work correctly. Meaning, I only wanted certain controls to be verified if they were NULL. So, I gave the 4 controls the "gl" extension. Since that part worked fine, I thought it would also work by adding the extension "rt" to the controls I want to change the visible property to. I didn't realize that was the wrong approach.

    With that said, I don't understand the modified code you provided. It appears it's checking to see if either "gl" or "rt" are NULL. That's not what I need. I need the "gl" to be determined if they are NULL and if they AREN'T, I need the controls visible property with the extension "rt" to be TRUE.

    However, I'm very new with writing Procedures and I'm sure it's just me not understanding what the code is doing...heck, I've taken the wrong approach with the extensions, can't write the code correctly .....so misunderstanding I'm guilty of.

    Sorry for the problems.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: Verify Null of Control (A2K)

    I didn't say that using "gl" and "rt" as name extensions was wrong, but that the way you tried to handle them in your code wouldn't do what you wanted.
    The code I posted does *not* test whether "gl" or "rt" is null, but whether the value of a control whose name ends in one of these two strings is null.
    Have you actually tried the code? If it doesn't do what you want, I think it's time you posted a stripped down version of your database. See <post#=401925>post 401925</post#> for instructions.

  8. #8
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Verify Null of Control (A2K)

    OK...sorry again for the misunderstanding and not saying things correctly.

    I can post a striped down version of the db, however, I'm not sure if that's necessary. I don't want to test both "gl" and "rt" to determine if the controls value is NULL only "gl".

    I'll try it this way....any control with the extension of "gl"...is tested to determine if the value is NULL....however, the controls with extension "rt" determines the visible property.

    If any "gl" value is Null, the user MUST input data for that control. Once ALL "gl's" value IS NOT NULL, then the "rt" controls must now be visible so the user can return to the "DataEntry_rt" tab.

    I am so sorry for so many problems I've caused.....really am I.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: Verify Null of Control (A2K)

    You don't have to apologize for causing problems - trying to solve problems is the goal of the Lounge!

    Up to now, you've tried to avoid referring to the form explicitly, but I think that's unavoidable. This implies that if you placed the VerifyIt function in a standard module, you must now move it to the form's own module.

    Try the following version of the code. You must replace TabControl with the name of the tab control on your form (twice); if it contains spaces or punctuation, put square brackets [ ] around it. I have assumed that the Data Entry tab is the first tab of this control.

    Public Function VerifyIt()
    Dim ctl As Control
    ' First, check whether a control on the Goals Met tab is blank
    For Each ctl In Me.Controls
    If Right(ctl.Name, 2) = "gl" And ctl.Parent.Name = "Goals Met" Then
    If IsNull(ctl.Value) Then
    MsgBox "You must make a selection for " & ctl.Name
    ctl.Visible = True
    ctl.SetFocus
    Exit Function
    End If
    End If
    Next ctl
    ' If not, display and activate the Data Entry tab
    Me.TabControl.Pages(0).Visible = True
    Me.TabControl.Value = 0
    End Function

  10. #10
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Verify Null of Control (A2K)

    Hans,

    Thanks for all your assistance....it's greatly appreciated.

    I modified the code you provided and all is well. (please see below)

    Happy New YEAR!!

    <pre>Public Function VerifyIt()
    Dim ctl As Control
    ' First, check whether a control on the Goals Met tab is blank
    For Each ctl In Me.Controls
    If Right(ctl.Name, 2) = "gl" And ctl.Parent.Name = "Goals" Then
    If IsNull(ctl.Value) Then
    MsgBox "You must make a selection for " & ctl.Name
    ctl.Visible = True
    ctl.SetFocus
    Exit Function
    End If
    End If
    Next ctl
    ' If not, display and activate the Data Entry tab
    DataEntry_rt.Visible = True
    MainMenu_rt.Enabled = True
    Problems_rt.Visible = True
    DataEntry_rt.SetFocus
    tGoalsComplete = -1
    Goals.Visible = False
    End Function
    </pre>

    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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