Results 1 to 3 of 3
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754

    Case Select Question for muti forms

    Hi all,


    Is there a way to make a case select statement dependent on what form is open? I have an address form to add addresses and then insert into a many to many table two fields from that form. See attached code below. The form I want to use is dependent on another form and I could use this same thing with different forms similar to the one in question.
    Code:
    Private Sub CboEmailType_AfterUpdate()
        If Me.NewRecord Then
            DoCmd.SetWarnings False
        DoCmd.RunSQL "INSERT INTO Person2EmailTbl (PersonID, EmailID) " & _
            "VALUES (" & CboPerson & ", " & EmailID & ")"
        DoCmd.SetWarnings True
        End If
    Forms!PersonFrm.Refresh
    End Sub
    I am wondering about maybe something like:

    SELECT CASE
    Case1

    If Me.NewRecord and if FormName then
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO Person2EmailTbl (PersonID, EmailID) " & _
    "VALUES (" & CboPerson & ", " & EmailID & ")"
    DoCmd.SetWarnings True


    Case 2

    If Me.NewRecord and if FormName then
    DoCmd.SetWarnings False

    DoCmd.RunSQL "INSERT INTO Person2EmailTbl (CompanyID, EmailID) " & _
    "VALUES (" & CboCompany & ", " & EmailID & ")"
    DoCmd.SetWarnings True
    End Case
    End If

    Somehting like that? Is that even possible?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    You don't need Select Case for just 2 conditions.

    Code can check if a particular form is open but it cannot be a subform.

    Code:
    If Me.NewRecord Then
        If CurrentProject.AllForms("Form1").IsLoaded Then
            'do this
        ElseIf CurrentProject.AllForms("Form2").IsLoaded Then
            'do this
        End If
    Else
        'do this
    End If

    Or forms can set a global variable or TempVars that can be read by any other form.


    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
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    cool, thanks June7

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

Similar Threads

  1. Select Case To Open Separate Forms
    By MdHaziq in forum Programming
    Replies: 6
    Last Post: 12-25-2017, 12:19 AM
  2. Pl sql case select
    By mrmmickle1 in forum Queries
    Replies: 1
    Last Post: 11-17-2015, 11:14 PM
  3. Replies: 1
    Last Post: 03-06-2015, 11:16 AM
  4. Select case help
    By killermonkey in forum Programming
    Replies: 7
    Last Post: 10-25-2013, 05:09 PM
  5. Replies: 4
    Last Post: 08-25-2012, 07:19 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