Results 1 to 3 of 3
  1. #1
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66

    Add Form starting with new record instead of (New)

    I have the form set to "Data Entry" but for some reason when the form opens to the first record to input instead of (New).

    What that means is... if I try to leave the form... I get the error "you must enter a value in the 'name' field".

    I have to hit (esc) button to clear everything out and my users aren't smart enough to do this!!!



    Here is the VBA that runs on this page. Is there something that is causing this to occur?

    Code:
    Option Compare Database
    Option Explicit
    Private blnGood As Boolean
    -------------------------------------------------
    Private Sub FindFileInput_Click()
    
        Dim f As Object
        Dim strSelectedpath As String
        Dim strSelectedFile As String
        Dim varItem As Variant
    
        Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
        
        If f.Show = -1 Then
            For Each varItem In f.SelectedItems
                 strSelectedpath = varItem & "#" & varItem
                 strSelectedFile = Split(strSelectedpath, "\")(UBound(Split(strSelectedpath, "\")))
                 Next varItem
                 Me![txtSelectedFile] = strSelectedpath
                 Me![txtFileName] = strSelectedFile
                 
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    
    Msg = "File association successful"
    Style = vbOKOnly + vbInformation + vbDefaultButton1
    Title = "Association"
    Help = "DEMO.HLP"
    Ctxt = 1000
    
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    
    If Response = vbYes Then    ' User chose Yes.
        MyString = "Done"    ' Perform some action.
    End If
                 
        End If
        Set f = Nothing
    
    End Sub
    -------------------------------------------------
    Private Sub Form_Current()
        If Me.NewRecord Then
            CreateBy = Environ("username")
        End If
    End Sub
    -------------------------------------------------
    Private Sub Form_Open(Cancel As Integer)
    If User.AccessID = 4 Then
        MsgBox "You are not authorized to open this form!", vbOKOnly + vbExclamation
        Cancel = True
    End If
    
    End Sub

  2. #2
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66
    Apparently I am smarter than I thought I was!!!

    Moving the following worked!

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
        If Me.NewRecord Then
            CreateBy = Environ("username")
        End If
    End Sub

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    How are you leaving the form? I don't see 'Exit' or 'Quit' or 'Cancel' button code.

    I see code in the Current event that populates something called CreateBy - is that a field or a global variable? Then the Click event is also populating fields. Either of those will initiate a record.

    EDIT: I see you figured it out. Congratulations!
    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. Problem with Form starting at the wrong position of a page
    By thebionicredneck2003 in forum Forms
    Replies: 2
    Last Post: 05-10-2013, 12:49 PM
  2. Replies: 1
    Last Post: 04-03-2012, 10:31 AM
  3. Replies: 2
    Last Post: 10-21-2011, 07:11 AM
  4. Replies: 1
    Last Post: 09-07-2011, 02:45 AM
  5. Replies: 3
    Last Post: 08-25-2011, 02:28 PM

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