Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    9

    Question Possible If statement for loading of a form

    Hello everyone I have question,

    I am trying to go about making a copying button for one of my forms in current database that I am building and I recently went about incorporating a "Copy" button which would take certain fields from one form (Item Form) and copy them over to a new record in a different form (Detail Form).



    I got the copy button to open up a "middleman" form which would be like a pop up box to ask them if they are wanting to actually copy over the data or not. Upon doing so and choosing the extra option I require them to choose (type of item drop down combo box). I would then take all the data in there and copy it to the (Detail Form) where it would populate the required fields that I have already filled out on the (Item Form) itself.

    Hopefully that is easy to understand a little bit it seems like a lot. my actual question is this up loading up (Detail Form) I want to go about doing a IF statement so that pressing the copy button it will run through the IF statement depending on if its a Yes/No and do accordingly.

    My thought about this that if I didn't want to copy populated fields over and wanted to go straight to the (Detail Form) how could I set up my code so that it just open the form and doesn't error out cause the following variable I am using isn't populated and thus would be Null and access pops up a error.

    So overall I want to find out if I can go about creating a way that depending on how you load up the form determines via the DoCmd code or just opening it normally from a switchboard or double clicking on the form itself.

    Here is my form_load code I have:

    Code:
     Private Sub Form_Load()
    Dim StrYesorNo As String
    
    'This is where I pre-determine the varible for my IF statement'
    StrYesorNo = "No"
    
    'This is where I am wanting to pull my variable from ***Only if I am going about using the copy button***'
    StrYesorNo = Forms!CopyTestForm2.Form!YesOrNo
    
    'Double check the value for the variable'
    MsgBox StrYesorNo
    
    'My IF statement' '<--- want this to only run if I go through the copy button on my (Item Form)'
    If StrYesorNo = "Yes" Then
    'Me.Item_Desc2.Text = Form!Item_Single_Add!Item_Desc
    'Me.Orig_Price_1.Text = Form!Item_Single_Add!Price1
    'Me.Orig_Price_2.Text = Form!Item_Single_Add!Price2
    'Me.Orig_Price_3.Text = Form!Item_Single_Add!Price3
    'Me.Orig_Price_4.Text = Form!Item_Single_Add!Price4
    ElseIf StrYesorNo = "No" Then
    End If
    
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I use OpenArgs argument of DoCmd.OpenForm (or OpenReport) to pass a parameter to form/report then If code can refer to the passed value.

    DoCmd.OpenForm "formname", , , , , "button" 'or whatever string value you want

    Then in the opening form:

    If Me.OpenArgs = "button" Then
    'do this
    End If
    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
    Join Date
    May 2012
    Posts
    9
    Ok, so after a little looking into it and after reading your suggestion. I was able to figure out a way to load up my form correctly and have it load without any errors coming up.

    Code:
    Private Sub Form_Load()
    'Way this form is setup to load is that depending on if they copy from Items Table
    'or if you just load this form up normally
    'Define the variables here:
    Dim StrYesorNo As String
    
    'When the form loads we see that it is looking for
    'a value for the variable which by defualt is set
    'to "No"
    StrYesorNo = "No"
    'IF statement that defines how the form should load up and if values need to
    'be copied over if coming from previous form (Items Table)
    
    If StrYesorNo = "No" Then
    '"No" = that it will open the form to see if anything was copied over
    'since there isn't it will return a "No" value
    
    DoCmd.OpenForm "CopyTestForm2", acNormal, , , acFormAdd
    StrYesorNo = Forms!CopyTestForm2.Form!YesOrNo
    DoCmd.Close acForm, "CopyTestForm2", acSaveNo
    End If
    If StrYesorNo = "Yes" Then
    '"Yes" = that you have chosen to go about copying over data
    'from the Items form and have chosen the correct publications
    'will return a "Yes"
    End If
    End Sub
    Here is my code that I used to get it working and also will marked this forum as solved!

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

Similar Threads

  1. Form Loading Slow From the Shared Folder
    By injanib in forum Forms
    Replies: 2
    Last Post: 06-25-2011, 03:45 AM
  2. Replies: 0
    Last Post: 02-15-2011, 01:43 PM
  3. Auto Loading a Form
    By toddbuckles in forum Programming
    Replies: 7
    Last Post: 12-28-2010, 04:20 PM
  4. Replies: 5
    Last Post: 12-27-2010, 06:59 PM
  5. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 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