Results 1 to 5 of 5
  1. #1
    PeterPeterson is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2012
    Posts
    7

    Iif in textbox in datasheet to run event to open form

    Using one of the templates from the Microsoft site I found the datasheet view of contacts that included a column with a hyperlink "Open" to open the contact's details very useful. The control source is
    Code:
    =IIf(IsNull([StudentID]),"New","Open")
    I have modified it to "Students" and use VB instead of a macro to open the student details form.
    Code:
    Private Sub Open_Click()
       
       If Not Me.NewRecord Then
          DoCmd.OpenForm "frmStudentDetails", _
            WhereCondition:="StudentID=" & Me.StudentID
       Else
          DoCmd.OpenForm "frmStudentDetails", acNormal, , acFormAdd
       End If
    
    End Sub
    This works well.

    I have applied exactly the same logic and code to qualifications,however, the word 'Open' is replaced with '#name?' letting you know immediately somethingis not quite correct.

    Clicking on the link results in the following error:
    "This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs."

    Control Source is
    Code:
    =IIf(IsNull([QualificationID]),"New","Open")
    The VB Event is:
    Code:
    Private Sub Open_Click()
    
    If Not Me.NewRecord Then
       DoCmd.OpenForm "frmQualificationDetails", _
         WhereCondition:="QualificationID=" & Me.QualificationID
    Else
       DoCmd.OpenForm "frmQualificationDetails", acNormal, , acFormAdd
    End If
    
    End Sub
    I hope someone can point out to me where my error is.
    Thanks
    Peter
    Last edited by June7; 10-06-2012 at 12:59 AM. Reason: Mod edit to fix CODE tags

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The acFormAdd is in the wrong position for both statements that use it. How did that happen if VBA intellisense popup tips is working. Don't know how the first one could run without error.

    DoCmd.OpenForm "frmQualificationDetails", acNormal, , , acFormAdd

    Also, try this for the OpenForm with WHERE CONDITION

    DoCmd.OpenForm "frmStudentDetails", , , "StudentID=" & Me.StudentID
    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
    PeterPeterson is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2012
    Posts
    7
    June7,
    Thank youforyour reply. I have corrected the two lines of code (I don't know how I missed the ",").
    I have also changed the WHERE CONDITION line.
    However, the issue I had is still there.
    I am still some way off getting this little application to a point I can replace our current paper based system we have at work. It is only used to manage 2 courses a month, but I am enjoying learning more about Access.
    I wish to use the StudentBrowser as the main screen and use the buttons on the header to open other browers from where the 'details' form can be opened to add new records.
    I have attached the database which may assist in locating my original error which is still present.
    Thanks again
    Peter
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think the form is corrupted. I created a new form and copy/pasted the controls from existing form to the new one and it works.
    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
    PeterPeterson is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2012
    Posts
    7
    June7,
    Thanks so much for your help - I recreated the form to find it works also.
    I have spent the last few days trying various things without success.
    Thanks again
    Peter

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

Similar Threads

  1. Replies: 8
    Last Post: 06-25-2014, 08:03 AM
  2. Replies: 1
    Last Post: 08-24-2012, 06:50 AM
  3. Replies: 3
    Last Post: 06-17-2012, 11:55 AM
  4. Replies: 3
    Last Post: 02-23-2012, 04:48 PM
  5. On Open form event not working
    By SPE_NY in forum Forms
    Replies: 2
    Last Post: 10-05-2011, 11:53 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