Results 1 to 4 of 4

Thread: validation

  1. #1
    Join Date
    Nov 2003
    Posts
    24

    Unanswered: validation

    Hi,

    I have a form with a field Parent Type which is visible only if the field Type is = 'minor defect'.

    What i am tryiong to do is create validation so that if Parent Type is visible it must have data entered otherwise if it is not visible then it is not required.

    I have used the following code on the click event of my save button on the form.

    If Forms!CR_DEFECT!TYPE = "CR" Or "DEFECT" Then
    Forms!CR_DEFECT!PARENT_TYPE.Required = False
    Else
    Forms!CR_DEFECT!PARENT_TYPE.validation = True
    End If

    I don't know if this is the way to do it but i am getting a type mismatch error anyway.

    Any help appreciated

    Parma

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Try this in the same place

    Select Case Me.TYPE

    Case "CR", "DEFECT"

    If IsNull(Me.parent_type) Then

    MsgBox "Parent type is required.", vbOKOnly, "REQUIRED FIELD IS BLANK"
    Me.parent_type.SetFocus
    Exit Sub

    Else
    'Dont worry parent_type has data

    End If

    Case Else
    'Dont worry parent_type not needed

    End Select
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Nov 2003
    Posts
    24
    Thanks Gareth got it working, used the following refined code from yours

    Select Case Me.TYPE

    Case "MINOR DEFECT"

    If IsNull(Me.PARENT_TYPE) Then

    MsgBox "Parent type is required.", vbOKOnly, "REQUIRED FIELD IS BLANK"
    Me.PARENT_TYPE.SetFocus
    Exit Sub
    End If
    End Select

    What does this part of the code do? can i take it out?

    Many thanks again

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Which part of the code?

    Do you mean the "Case Statement" ie Select Case etc?

    Case statements usually only used if there are several different possibilities you want to test for:

    Select Case me.somevariable 'Declaration of case statement

    Case 1 'ie is the value of somevariable 1
    <Code to do something here>

    Case 2 'ie is the value of somevariable 1
    <Code to do something different here>

    Case 456 'ie is the value of somevariable 456
    <Code to do something different againhere>

    Case else 'somevariable Is neither of the above
    <Maybe do nothing>

    end select ' End of case statement

    When the code gets to select case, it jumps to the case that refers to the
    value of the variable, runs the code for that case then runs through to the end select bit. Hope that makes sense

    You can just as easily use "Nested IF Statements" but I used a case statement just as an example.

    if Me.TYPE= "MINOR DEFECT" then

    If IsNull(Me.PARENT_TYPE) Then

    MsgBox "Parent type is required.", vbOKOnly, "REQUIRED FIELD IS BLANK"
    Me.PARENT_TYPE.SetFocus
    exit sub 'Only if you have other code that runs after this bit
    End If

    end if

    Have a look at the MSDN site which should have good explanations of using Select Case / If Statements etc. These would may be referred to as "Logic Structures"

    A resource for an intro to VBA is here:

    http://msdn.microsoft.com/library/de...acbachap02.asp

    Im sure others can post more links.
    Last edited by garethdart; 12-31-03 at 08:16.
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

Posting Permissions

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