Results 1 to 6 of 6
  1. #1
    zuerin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    4

    Question Save as Draft but mandatory field is not required

    Hi,

    I was trying to solve this problem but i'm stuck..appreciate if you guys can assist me..
    I have a form that will check for mandotary field before exit but my customer requested if they can save the form as draft without have to fill in all the mandatory field.

    Therefore I've added "Draft" in the Status list box but when i save the form it still need me to fill in all the mandotary field.

    Private Sub Command66_Click()

    'On Error GoTo errorStage
    If IsNull(Me.t_id) Or Trim(Me.t_id) = "" Then
    If status = "Draft" Then


    addTable Me.Form.Controls, "Record", "t_id"

    MsgBox "Saved"
    Forms![f_main].subform.Requery
    DoCmd.Close acForm, "f_input"

    Else
    If myValidate(Me.Form.Controls, requiredColor, 255) = True Then
    addTable Me.Form.Controls, "Record", "t_id"

    MsgBox "Saved"
    Forms![f_main].subform.Requery
    DoCmd.Close acForm, "f_input"
    Else
    MsgBox "Please input all required fields"








  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Is this a bound form? Does the form RecordSource include fields that are set as Required?

    I've never seen that addTable method. Are you creating a new table or a record in a table?

    You are not showing the complete procedure. Where are the End If lines? Post code between code tags and it will retain indentation for easier reading.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    zuerin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    4
    fyi, this database was developed by someone else...i was trying to help my customer as they are having problem with this db...and as usual if you manage to solve one they will come one out with other stuff ...ok this is Unbound form.

    Let me paste u the original code :
    Private Sub Command66_Click()

    'On Error GoTo errorStage
    If IsNull(Me.t_id) Or Trim(Me.t_id) = "" Then
    If myValidate(Me.Form.Controls, requiredColor, 255) = True Then
    addTable Me.Form.Controls, "Record", "t_id"


    MsgBox "Saved"
    Forms![f_main].subform.Requery
    DoCmd.Close acForm, "f_input"
    Else
    MsgBox "Please input all required fields"
    End If
    Else

    If myValidate(Me.Form.Controls, requiredColor, 255) = True Then
    editTable Me.Form.Controls, "Record", "t_id=" & Me.t_id, "t_id"

    MsgBox "Saved"
    Forms![f_main].subform.Requery
    DoCmd.Close acForm, "f_input"
    Else
    MsgBox "Please input all required fields"
    End If
    End If
    errorEnd:
    Exit Sub
    errorStage:
    MsgBox "The record might not be saved - " & Err.DESCRIPTION

    End Sub

    Module for addtable :
    Sub addTable(f As Controls, t As String, primaryKey As String)
    Dim x As Control
    Dim rst As Recordset

    Set rst = CurrentDb.OpenRecordset("select * from " & t)
    rst.AddNew
    For Each x In f
    If x.ControlType = acTextBox Or x.ControlType = acListBox Or x.ControlType = acComboBox Or x.ControlType = acCheckBox Then
    If x.Name <> primaryKey And Right(x.Name, 3) <> "_ex" Then
    If InStr(1, x.Name, "_date") > 0 Then
    If IsNull(x) Or Trim(x) = "" Then
    x = Null
    End If
    End If




    rst(x.Name) = x
    End If

    End If
    Next x
    f.Item(primaryKey) = rst(primaryKey)

    rst.Update
    rst.Close
    WriteAudit f, f.Item(primaryKey), t, primaryKey, "Add"
    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Hard to read and follow the logic.

    Have you step debugged? Follow the code as it executes, determine where it deviates from expected behavior, fix, repeat.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    zuerin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    4
    may i know how to do that?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Is this redundant? NFL Draft DB
    By GenericHbomb in forum Database Design
    Replies: 2
    Last Post: 08-01-2011, 09:46 AM
  2. Exporting to Draft Email
    By swimmermx in forum Import/Export Data
    Replies: 0
    Last Post: 07-28-2010, 05:16 PM
  3. Replies: 2
    Last Post: 04-30-2010, 09:43 AM
  4. Replies: 8
    Last Post: 03-29-2010, 10:20 AM
  5. Required Field Help
    By brandonb in forum Access
    Replies: 4
    Last Post: 11-13-2009, 11:18 AM

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