Results 1 to 6 of 6
  1. #1
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92

    Red face Title: Giving Wrong Name

    When entering data, I chose a name from the list and I can either view what I've added for that person or enter new data. The word "View" and "New" is clickable on the form. View to see the complete info for that person and New to input a new information for that person.

    When I clicked New, a new form will pop up (frmCertificationEdit) showing all info and the title has "Recertification Details for " and the name of the person. When I clicked View same form is showing (frmCertificationEdit) but for some reason the title stays to wrong name even if the name I chose is different. I'm using same form for both View and New but why is it when I clicked View, the name of the person don't change to whoever I chose from the list?

    Here's the Event Procedure in On Click:


    Private Sub Edit_Click()
    On Error GoTo Err_Edit_Click


    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim tempStr As String

    stDocName = "frmCertificationEdit"
    If Me.Edit.Value = "NLN" Then
    MsgBox "This item has been flagges as 'No Longer Needed'.", vbExclamation + vbOKOnly
    GoTo Exit_Edit_Click
    ElseIf Me.Edit.Value = "View" Then
    modMain.certificateCount = Me.tbCertificationCount.Value
    stLinkCriteria = "1=1" & " AND " & "tblCertifications.[CertDateID] = " & Me.CertDateID.Value & ""
    DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
    ElseIf Me.Edit.Value = "New" Then
    modMain.certificateCount = Me.tbCertificationCount.Value
    DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
    If IsNull(Form_frmCertifications.cbFullName.Column(1) ) Then
    tempStr = Form_frmCertifications.cbFullName.Value & ", " & Form_frmCertifications.tbFirstName
    Else
    tempStr = Form_frmCertifications.cbFullName.Column(1) & ", " & Form_frmCertifications.tbFirstName
    End If
    Form_frmCertificationEdit.cbempid.Locked = False
    Form_frmCertificationEdit.cbempid.Text = tempStr
    Form_frmCertificationEdit.labelTitle.Caption = "Recertification Details for " & tempStr
    Form_frmCertificationEdit.cbCertDepartment = Form_frmCertifications.empdept.Column(0)
    Form_frmCertificationEdit.cbcertSupervisor = Form_frmCertifications.empSupervisor
    Form_frmCertificationEdit.cbCertDepartment.SetFocu s
    Form_frmCertificationEdit.cbempid.Locked = True
    End If
    Exit_Edit_Click:
    Exit Sub
    Err_Edit_Click:
    MsgBox Err.Description
    Resume Exit_Edit_Click
    End Sub

    Your help is appreciated.

    Thanks,
    netchie

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Did you step debug? Set breakpoint, follow code as it executes. Find where it deviates from expected behavior, fix, debug again.
    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
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In looking at the code, you never assigned a value for "tempSt" in the ELSEIF Me.Edit = "View" clause. I don't know it this will run correctly, but I modified your code.

    Code:
    Private Sub Edit_Click()
       On Error GoTo Err_Edit_Click
       Dim stDocName As String
       Dim stLinkCriteria As String
       Dim tempStr As String
    
       stDocName = "frmCertificationEdit"
       If Me.Edit.Value = "NLN" Then
          MsgBox "This item has been flagges as 'No Longer Needed'.", vbExclamation + vbOKOnly
    
       ElseIf Me.Edit = "View" Then
          modMain.certificateCount = Me.tbCertificationCount
          stLinkCriteria = "1=1" & " AND " & "tblCertifications.[CertDateID] = " & Me.CertDateID
          DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
    
          If IsNull(Forms!frmCertifications.cbFullName.Column(1)) Then
             tempStr = Forms!frmCertifications.cbFullName & ", " & Forms!frmCertifications.tbFirstName
          Else
             tempStr = Forms!frmCertifications.cbFullName.Column(1) & ", " & Forms!frmCertifications.tbFirstName
          End If
    
          Forms!frmCertificationEdit.labelTitle.Caption = "Recertification Details for " & tempStr
      
       ElseIf Me.Edit = "New" Then
          modMain.certificateCount = Me.tbCertificationCount
          DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
    
          If IsNull(Forms!frmCertifications.cbFullName.Column(1)) Then
             tempStr = Forms!frmCertifications.cbFullName & ", " & Forms!frmCertifications.tbFirstName
          Else
             tempStr = Forms!frmCertifications.cbFullName.Column(1) & ", " & Forms!frmCertifications.tbFirstName
          End If
    
          Forms!frmCertificationEdit.cbempid.Locked = False
          Forms!frmCertificationEdit.cbempid = tempStr
          Forms!frmCertificationEdit.labelTitle.Caption = "Recertification Details for " & tempStr
          Forms!frmCertificationEdit.cbCertDepartment = Forms!frmCertifications.empdept.Column(0)
          Forms!frmCertificationEdit.cbcertSupervisor = Forms!frmCertifications.empSupervisor
          Forms!frmCertificationEdit.cbCertDepartment.SetFocus
          Forms!frmCertificationEdit.cbempid.Locked = True
       End If
    
    Exit_Edit_Click:
       Exit Sub
    Err_Edit_Click:
       MsgBox Err.Description
       Resume Exit_Edit_Click
    End Sub
    I also cleaned up some other things I saw: you don't need to add ".Value" as that is the default property.

    You don't need the "GOTO" line because the code will 'fall through' to the the END IF and exit properly.


    And the proper way (not the only way) to refer to other forms is:
    Forms!formName.controlName, not "Form_frmCertificationEdit"


    Last edited by ssanfu; 09-15-2011 at 10:14 AM. Reason: formatting

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Actually, in VBA code, both versions of referring to forms (as well as reports) will work. Access requires the Forms/Reports class and ! syntax.
    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
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Best to NOT use the Form_ syntax though as it can have unintended side effects.

  6. #6
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92
    Thanks guys for checking this for me. You guys are always nice and ready to help users in need like me .

    Thanks ssanfu for helping out. Yeah, it worked!

    netchie

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

Similar Threads

  1. No useful title
    By cap.zadi in forum Access
    Replies: 1
    Last Post: 09-05-2011, 09:50 AM
  2. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 06:04 PM
  3. Replies: 2
    Last Post: 05-17-2011, 02:40 PM
  4. NoData() still giving me an error.
    By cowboy in forum Programming
    Replies: 3
    Last Post: 04-08-2010, 12:26 PM
  5. Title Label In Subforms
    By vCallNSPF in forum Reports
    Replies: 4
    Last Post: 12-08-2009, 06:20 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