UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Multiple Openargs Values To Be Used In Different Areas Of The Form/different Ways, Access 2013    
 
   
Jdb_1229
post Jan 10 2017, 09:45 AM
Post#1



Posts: 27
Joined: 13-July 16



I swear everytime I think I have taken care of the problem something else comes up. dazed.gif

I have been working on this database for the owner of my company and i am not at all a computer coder much less an access coder. I have developed codes throughout this database thanks to alot of the advice I have recieved from here so here I am again.

I have a main database page, not a switchboard but a continuous form with the basic information for our customers, I have a relationship between the CompanyID on FrmDatabaseInformation and the CompanyID on FrmAdditionalContacts. I was able to successfully create an OpenArgs function that when I pressed a "New" button on my FrmAdditionalContacts it would copy the CompanyID from FrmDatabaseInformation so that the newly entered contact was still connected to the company. I even figured out how to hide the add line with the AllowAdditions = False function. I am now running into another issue.

I still need the form to do what was described above but I also now need to bring over the information from a field called No Work. This field, located in the FrmDatabaseInformation, designates that if the owner has decided we no longer wish to do work with this customer we should still be able to see the data entered for them; however, we should not be able to edit any of it. This is so if someone else accesses the database and is checking to see if we should perform work for them they know we can't. The problem is that I need to make sure that if the contact button for Record X, that is a no work company, is selected the user can see the data but not enter or change anything.

I will list the code I currently have below:

Open Args
Located on the On click of the CmdAdditionalContacts button on FrmDatabaseInformation
CODE
Private Sub CmdOpenContacts_Click()
If Me.CompanyID > 0 Then
    DoCmd.OpenForm "FrmAdditionalContacts", acNormal, , "CompanyID =" & CompanyID, , , Me.CompanyID
    
Else
    DoCmd.OpenForm "FrmDatabaseInformation", acNormal, , , acFormAdd
End If

End Sub


Located on the on click of the CmdNewRecord button on the FrmAdditionalContacts
CODE
Private Sub CmdNewRecord_Click()
Dim strCompanyID As String

strCompanyID = Nz(Form_FrmAdditionalContacts.OpenArgs)

Me.AllowAdditions = True

If Len(strCompanyID) > 0 Then
DoCmd.GoToRecord , , acNewRec
Me.CompanyID.Value = strCompanyID
End If

End Sub


This works beautifully!

Also, code for the No Work selection
CODE
Private Sub Form_AfterUpdate()


If Me.No_Work = True Then
    Me.AllowEdits = False
    Me.AllowDeletions = False
Else
    Me.AllowAdditions = True
    Me.AllowEdits = True
    Me.AllowDeletions = True
End If

End Sub

Private Sub Form_Current()
If Me.No_Work = True Then
    Me.AllowEdits = False
    Me.AllowDeletions = False
Else
    Me.AllowAdditions = True
    Me.AllowEdits = True
    Me.AllowDeletions = True
End If

End Sub


I have found some information regarding multiple open args and found code that use Parse Text as well as code that uses String Functions and Splitting the Open Args. I am not partial either way (obviously in part because I am having trouble understand it) so if anyone could give me some advice or help with some of the issues I am having I would really appreciate it. Thank you!



Go to the top of the page
 
ADezii
post Jan 10 2017, 10:37 AM
Post#2



Posts: 1,782
Joined: 4-February 07
From: USA, Florida, Delray Beach


There are several ways that you can accomplish this, I'll show you just one. Let's suppose you have a Form named Form1 that is Bound to an Employees Table. On this Form you have two Text Boxes named txtID and txtEMail that are Bound to the [ID] and [EMail] Fields of tblEmployees. You now wish to pass these two Values as Arguments when you Open a Form named Form2. One Method is to pass a Comma-Delimited List of Arguments to OpenArgs then retrieve them using the Split() Function. In the example, I will pass both the [ID] and [EMail] Values to Form2 when I Open it, then retrieve them in Form2's Open() Event:
  1. Pass Values using OpenArgs:
    CODE
    With Me
      DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acWindowNormal, ![txtID] & "," & ![txtEMail]
    End With
  2. Retrieve these Values in the Open() Event of Form2:
    CODE
    Private Sub Form_Open(Cancel As Integer)
      Debug.Print "ID    : " & Split(Me.OpenArgs, ",")(0)
      Debug.Print "E-Mail: " & Split(Me.OpenArgs, ",")(1)
    End Sub
  3. OUTPUT in Debug Window for multiple Code Executions:
    CODE
    ID    : 1
    E-Mail: nancy@northwindtraders.com

    CODE
    ID    : 2
    E-Mail: andrew@northwindtraders.com

    CODE
    ID    : 3
    E-Mail: jan@northwindtraders.com

    CODE
    ID    : 6
    E-Mail: michael@northwindtraders.com
Go to the top of the page
 
Jdb_1229
post Jan 10 2017, 12:30 PM
Post#3



Posts: 27
Joined: 13-July 16



ADezii, you are amazing! notworthy.gif that almost fixed my issue. I am now running into a problem where the CompanyID is being brought over but the No_Work options is not. Here is what I have:
(There was one piece I had to alter because it gave me an error code)

CODE
If Me.CompanyID > 0 Then
    DoCmd.OpenForm "FrmAdditionalContacts", acNormal, , "CompanyID =" & CompanyID, acFormEdit, acWindowNormal, Me.CompanyID & "," & Me.No_Work
Else
    DoCmd.OpenForm "FrmDatabaseInformation", acNormal, , , acFormAdd
End If

End Sub


and

CODE
Private Sub Form_Open(Cancel As Integer)
  Debug.Print "CompanyID: " & Split(Me.OpenArgs, ",")(0)
  Debug.Print "No Work: " & Split(Me.OpenArgs, ",")(1)
  
If Me.No_Work = "Yes" Then
    Me.AllowAdditions = False
    Me.AllowDeletions = False
    Me.AllowEdits = False
    Me.CmdNewRecord.Visible = False
Else
    Me.AllowAdditions = True
    Me.AllowDeletions = True
    Me.AllowEdits = True
    Me.CmdNewRecord.Visible = True
End If

End Sub


as well as
CODE
Private Sub CmdNewRecord_Click()
Dim strCompanyID As String

strCompanyID = Nz(Form_FrmAdditionalContacts.OpenArgs)

Me.AllowAdditions = True



    If Len(strCompanyID) > 0 Then
    DoCmd.GoToRecord , , acNewRec
    Me.CompanyID.Value = strCompanyID
    End If
    

End Sub


CompanyID is pulling over but No work is not an it may be a mistake I made in spelling or something. Thank you again for your help!
Go to the top of the page
 
ADezii
post Jan 10 2017, 01:33 PM
Post#4



Posts: 1,782
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. What results do you get with?
    CODE
    Debug.Print "No Work: " & Split(Me.OpenArgs, ",")(1)
  2. Is [No_Work] a Check Box?

This post has been edited by ADezii: Jan 10 2017, 01:35 PM
Go to the top of the page
 
Jdb_1229
post Jan 11 2017, 08:13 AM
Post#5



Posts: 27
Joined: 13-July 16



Still nothing, unfortunately. And yes it is, my boss wants it that way on the main form where the data is being retrieved from. However, the screens where the data is being transmitted to will have a hidden No Work field so if there is another format I can put it in I would be happy to. Thank you so much for all of your assistance. I will say that I am having no debug issues(which is unusual for me woohoo.gif ) it just isn't performing the action I need it to at this point.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    22nd September 2017 - 10:53 PM