Results 1 to 2 of 2
  1. #1
    frankq is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    5

    Extras for my form

    I have, thanks to some help from Rural Guy, managed to get the simple form I created to input records to my table,and to do what I wanted it to.


    Having got that working it would be nice to add a few extras to speed up data entry.

    If at all possible I would like to be able to use some conditions to automatically fill in a field
    I have a field called class which will always be either 1 or 2, depending on this another field called Earth test will either be Yes or n/a.
    I need some way of saying 'If class is 1 then put yes in the box If class is 2 then put n/a in the box'

    I also have a field called Pass I set this as a simple yes/no on the table. How do I set this up on the form so that it will do the same?
    My apologies if this seems to simple for the experts out there
    but this is my first entry into the world of Access and it's certainly more complex than I thought.

  2. #2
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    You have two field with names class and Earth test, if class value is 1 then Earth test value should be Yes, otherwise should be n/a?

    This can be done through VBA coding:
    1) Open your form in design view
    2) Right click on class field and goto property option.
    3) In the Property window, goto Event tab of the class field
    4) Select After update event of the class field, you will get VBA window like with this code:

    Private Sub Class_AfterUpdate()

    End Sub

    ============
    Write this line of code before the End Sub:


    If me.class.value = 1 then
    me.[Earth test].value = "Yes"
    Else
    me.[Earth test].value = "n/a"
    End If
    your code will look like this:

    Private Sub Class_AfterUpdate()
    If me.class.value = 1 then
    me.[Earth test].value = "Yes"
    Else
    me.[Earth test].value = "n/a"
    End If
    End Sub
    assuming that your earh test field data type is text.
    Also please avoid naming the fields names to reserve word like. field, type, class, etc. these would lead to error while coding. second, avoid spacing between field names [Earth test] otherwise you have to use [ ] around the fields names while referencing in the code.
    The field Earth test could be written as Earth_test OR EarthTest is a better way to represent.

Please reply to this thread with any new information or opinions.

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