Results 1 to 9 of 9
  1. #1
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212

    Using IIf statement in event procedure for onclick. first half works, but not when cdmarker =ss

    I'm using this IIf statement in event procedure for onclick. If cdmarker =cd, it works, but if it equals ss, I want it to do the else. Any help would be appreciated.

    Private Sub Copy411_Click()



    'If FIsLoaded("FEditHUD") Then
    If Forms!FEditHud!cdmarker = "cd" Then
    Call CopyTwoFields("FSettlementPage1","Text694", "text700", "K411c", "K411")
    Else
    Call CopyTwoFields("FSettlementPage1","J112c", "J112", "K411c", "K411")
    End If
    'End If

    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    What happens when code runs - error message, wrong results, nothing?

    What is cdmarker - a field name? Is this a text type field?

    This code is behind form FEditHud?

    What are Text694 and text700 - textboxes on FEditHud? Why are these references within quote marks - do you need the values of the textboxes or the textbox names passed as argument parameters?
    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 XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And what is the code for the subroutine "CopyTwoFields"?

    In addition to June's comments, I would probably use the "Select Case" construct instead of "IF()"
    Code:
    Private Sub Copy411_Click()
    
        Select Case Forms!FEditHud!cdmarker
            Case "cd"
                Call CopyTwoFields("FSettlementPage1", "Text694", "text700", "K411c", "K411")
            Case "ss"
                Call CopyTwoFields("FSettlementPage1", "J112c", "J112", "K411c", "K411")
            Case Else
                MsgBox "Oops!!"
        End Select
    
    End Sub

    My $0.02 worth...........

  4. #4
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    beat me to it.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Further to the comments so far, and along the line of June's questions, it is easier for you and for anyone trying to read/maintain the code, if you would give meaningful names to fields, objects, controls etc.
    Text694 , text700 mean nothing to the application nor anyone trying to follow the logic flow.
    This is all part of design, allocate time to do the analysis and design.

    When you are posting code, use code tags --highlight the code involved then click on the # in the header of the reply area.

    If you are doing any amount of Access/vba work, I strongly recommend you obtain these 2 free utilities:
    SmartIndenter and MZTools for VBA.
    Good luck with your project.

  6. #6
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    I have used the Selected Case suggested by Steve and it works great. The cd marker field is on a Form called FEditHUD which allows me to choose which view of the data entry form I will use. The event procedure is behind the data entry form not FEditHUD.
    Text 694 etc are text boxes on the data entry form that look up data on a third form. I can then reference these values when I am in the data entry form. I went through a lot of catch 22's to get here. So I am happy with the results. Thanks for the help.

  7. #7
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Thanks for the example of the Select Case. I have not used that in an event procedure. I have several other instances that I can now improve on. It worked like a dream.

  8. #8
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Function CopyFields(Source$, Destination$)

    'Copy fields fromform Source$ to form Destination$.
    'Only fields withmatching ControlSource names will be copied.

    On Error ResumeNext 'Disable error trapping

    For COUNTER = 1 ToForms(Source$).Count
    'Try to get acontrol source for control Counter.
    ControlField$ =Forms(Source$)(COUNTER).ControlSource

    'Did we get acontrol source? (Err=0)
    If Err = 0 Then
    'We have asource. Try to copy it to the destination
    Forms(Destination$)(ControlField$)= Forms(Source$)(ControlField$)
    End If
    Err = 0 'Clear any errors
    Next COUNTER
    End Function

  9. #9
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Thanks for the advise, and I will look at the utilities suggested.

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

Similar Threads

  1. OLEunbound onclick event
    By thangasiva in forum Forms
    Replies: 1
    Last Post: 03-26-2015, 10:55 AM
  2. Replies: 1
    Last Post: 03-29-2014, 07:46 PM
  3. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  4. Onclick event
    By tmcrouse in forum Forms
    Replies: 3
    Last Post: 09-18-2010, 01:10 PM
  5. OnClick event
    By HotTomales in forum Forms
    Replies: 1
    Last Post: 12-24-2009, 08:10 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