Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can a Outlook form force someone to enter data ?

    In my form I have the Users enter their information on what they want. Is there a way that I can force them to enter something otherwise the form will not be "Sent"? I am trying to do this in the Update section that will save the information to a database.

    Sub Update()
    Dim Obe
    Dim MyDB
    Dim Rst
    Dim Rsm

    'On error resume next
    Set Dbe = Application.CreateObject("DAO.DBEngine.35")
    If Err.Number <> 0 Then
    MsgBox Err.Description & "- functions may not work correctly" _
    & Chr(13) & "Please make sure DAO 3.5 is installed on machine"
    Exit sub
    End If

    Set MyDB = Dbe.Workspaces(0).OpenDatabase("C:cigarsroom.mdb")
    RequestNum = UserProperties.Find("jobnum").Value
    Set Rst = MyDB.OpenRecordset("select * from dbTTrans where tasknum = " & RequestNum)

    If Rst.EOF = True And Rst.BOF = True Then '
    Set Rst = MyDB.OpenRecordset("dbTTrans")
    rst.addnew
    Else
    rst.edit
    End if

    ' Access side Outlook side
    Rst.fields("Tasknum") = UserProperties.Find("Jobnum").Value
    Rst.fields("cname") = UserProperties.Find("client").Value
    Rst.fields("vol1") = UserProperties.Find("volser1").Value
    Rst.fields("vol2") = UserProperties.Find("volser2").Value
    Rst.update
    Rst.close

    ' Update DBTask
    RequestNum = UserProperties.Find("jobnum").Value
    Set Rst = MyDB.OpenRecordset("select * from dbtask where tasknum = " & RequestNum)

    If Rst.EOF = True And Rst.BOF = True Then '
    MsgBox "Empty record or not found" 'error hand
    End If
    Rst.Close
    MyDB.Close
    End Sub
    '-=-=-=-=-=-=-=-

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a Outlook form force someone to enter data ?

    Why not just use simple field validation? I guess I don't understand what the problem is (and neither does anyone else, I guess by that zero in the replies column [img]/w3timages/icons/nope.gif[/img]).

    By "sent" you mean to the database? I don't see any Outlook object references in the code, so you don't mean sent as in send an email, correct?

    In Access you can use the Unload event (which fires before the form is removed from the screen) to validate entry fields. Look up the Unload event and use that Cancel parameter to cancel the unload if the fields you want to test don't validate. That's the "proper" way to force the user to enter something or the correct thing before proceeding. Does that help?

    <font color=448800>Private Sub Form_Unload(Cancel As Integer)</font color=448800>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a Outlook form force someone to enter data ?

    Yes, It wasn't very clearn. I have a button setup to "send" the Form/message to us. There are four different fields that need to be filled out each time a form is sent.

    In my cmdbutton, I have a module that goes out and saves the information to an Access 97 db. I am thinking of adding a new "step" before this one that will look for a "blank" field and display a message telling the user they need to fill in this field.

    Up to this part I can do this. My problem is, if the field is blank how do I stop the cmdbutton from running and make it go back to the form so they can fill it out.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a Outlook form force someone to enter data ?

    That's where the unload event comes in. Your command button calls form_unload (and that's ALL). That sub tests for the blank field(s). If it's blank, your code sets CANCEL = TRUE, displays a nice reminder msgbox, sets the focus on the blank field then exists the sub. Viola! The user is prevented from proceeding and the IP is flashing on the blank field.

    I love this functionality. Somebody at MS loves us...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a Outlook form force someone to enter data ?

    Seem's I am missing something. THis is my Command button

    '-=-=-=-=-=-=-=-=-=-
    function Item_Send()
    Blankfield 'Supposed to check field for blanks.
    update 'This goes out and saves the info. If OK
    end function
    '-=-=-=-=-=-=-=-=-=-

    THis is the part were I check for the blank.

    '-=-=-=-=-=-=-
    Sub Blankfield()
    If UserProperties.Find("Client").Value = "" then
    Msgbox "This field must be filled and not blank", vbInformation
    Cancel = TRUE
    Else
    End if
    End Sub
    '-=-=-=-=-=-=-

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can a Outlook form force someone to enter data ?

    Daniel,

    Here's some skeletal code that I know works and shows the unload cancel in action:

    <pre>Private Sub cmdClose_Click() 'This is the Close/Exit button on the form
    On Error Resume Next

    DoCmd.Close 'The close event fires the Unload event first. So the code below executes before the close event finishes.

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    txtName.SetFocus
    If txtName.Text = "" Then
    Cancel = True
    MsgBox "Name cannot be blank. Try again.", vbCritical
    txtName.SetFocus
    Else
    Call Update
    End If

    End Sub
    </pre>


    How's that?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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