Results 1 to 9 of 9

Thread: Form Controls

  1. #1
    Join Date
    Jul 2003
    Location
    Portugal
    Posts
    111

    Unanswered: Form Controls

    Excuse me... I'm near of out of self-control with forms controls...

    I - The facts

    1. In the form there are white and gray fields
    2. White field needs user enter data
    3. Gray field is optional

    2 - The question

    I need to say user that form is not complete, because he forgot to enter data (somewhere... into a white field)

    3 - Thanks
    After hours, I'm crazy...

    I'll appreciate very much your help.

    Ruas

  2. #2
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Re: Form Controls

    jmruas,

    One solution would be to go to the Table design, Select the Field that is the one that HAS to have data in it and go down to the Table/Properties window below and where it says Required....click Yes in that. Now, that field will Have to have data in it to move on.

    Bud

  3. #3
    Join Date
    Oct 2003
    Location
    Rotterdam
    Posts
    17
    more charming is to write an "form_before update procedure"

    looks something like this
    -------------------------------------------------------------------------
    Private Sub checkdata()


    Dim mes As String

    If IsNull(Me.field1) Then
    mes "field 1 is empty" & Chr(13)
    End If

    If IsNull(Me.field2) Then
    mes = mes & "field 2 is also empty & Chr(13)"
    End If

    If mes = "" Then
    checkdata = True
    Else
    msgbox mes
    checkdata = False

    End Sub

    -------------------------------------------------------------
    Private Sub Form_BeforeUpdate(Cancel As Integer)

    if checkdata = false then
    cancel = true
    end if


    End Sub
    Last edited by peter1970; 02-04-04 at 17:02.
    Peter Dorsman

  4. #4
    Join Date
    Jan 2004
    Posts
    75
    I asked a similar question last week.... merely having the field set to required does not keep the record from saving. My users repeatedly begin to enter a new record, get interrupted, then come back and restart, creating two records... one of which is incomplete. It's an enormous headache.

    I've been working all day on using "If... IsNull..." but I have so many required fields that this is more of headache and STILL does not delete the partial record if the user chooses to abort.

  5. #5
    Join Date
    Nov 2003
    Location
    San Francisco, CA USA
    Posts
    59
    I'd try Peter's approach. Since it's tied to a BeforeUpdate property, no record should be written until after that code runs. You'd have to have the appropriate routine termination code so that it exited without writing the record. (Notice his "cancel=true" statement.)

    Choosing the wrong Event property can do stuff like what you are describing.

    The other option, if you're up to it, is to look into transaction processing. But really, Peter's idea is a lot easier to manage for small to mid-sized databases.

    Magee

  6. #6
    Join Date
    Jan 2004
    Posts
    75
    Sorry to steal your audience here Ruas, but I'm still stuck.

    I want to give the user the option to either return to the form and finish the record, or cancel altogether.

    I tried this after reading your post... No matter what the reply, it closes the form and STILL saves the darned partial record. What's this Cancel = true thing doing anyway??

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me![SSN]) Then
    If MsgBox("YOU MUST ENTER A SNN!!", vbOKCancel, "EMPTY REQUIRED FIELD") = vbCancel Then
    Cancel = True
    DoCmd.Close
    End If
    End If
    End Sub

  7. #7
    Join Date
    Jul 2003
    Location
    Portugal
    Posts
    111
    My dear Sublimsos, your mess is in the right place. Don't worry! And that's connected with my problem.

    When we have lots of fields, and one of them can't be filled in that moment, it make no sense to denie to save the record in that moment and later to complete it.

    With a msgbox, user knows there are something to do in the next time.

    I think the way is to use code. And what code? Once more I think (I think too much!) that must be something around controls, like:

    Dim ctl As Control
    For Each ctl In Me.Controls
    ... ...

    I have found no code that meets what I need and I'm not an expert with this

    So, I'm glad, very glad with all approach you bring here. This is a great place with amazing people.

    Thank you all,

    Ruas

  8. #8
    Join Date
    Nov 2003
    Location
    San Francisco, CA USA
    Posts
    59
    Can you upload a copy of your database so we can figure out what the problem is? I think the problem is relatively easily solved but I'm having trouble with why these suggestions aren't working. It may help to see what you've done.

    Magee

    Originally posted by sublimsos
    Sorry to steal your audience here Ruas, but I'm still stuck.

    I want to give the user the option to either return to the form and finish the record, or cancel altogether.

    I tried this after reading your post... No matter what the reply, it closes the form and STILL saves the darned partial record. What's this Cancel = true thing doing anyway??

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me![SSN]) Then
    If MsgBox("YOU MUST ENTER A SNN!!", vbOKCancel, "EMPTY REQUIRED FIELD") = vbCancel Then
    Cancel = True
    DoCmd.Close
    End If
    End If
    End Sub

  9. #9
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8

    Here on I use

    But this can be us in any form

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
               Call Checkit(Me)
    End Sub
    then in a module paste this


    Code:
    Sub Checkit(This_Form As Form)
    Dim CurrentForm As Form
    Dim Item As Variant
    Set CurrentForm = This_Form
    For Each Item In CurrentForm
        If Item.ControlType = acTextBox Then
            If Item.BackColor = 16777215 Then 'what color am i checking
                Item.SetFocus
                If Len(Item.Text) = 0 Then
                    MsgBox Item.Name & " Is Blank"
                    Exit For  'that current Item should have focus
                End If
            End If
        Else
        
        End If
    Next
    Set CurrentForm = Nothing
    End Sub
    just remeber to change the Controltype to the right one
    and the BackColor to the right colour
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

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