Passing Values between forms

I am trying to link  to forms.  I have a button on the main form 
(frmCompanies) that needs to open another form when a button is clicked. The 
new form that opens is frmScheduledActivities. When it open it needs to check 
to see if there is an existing record (scheduled activity) for the company 
and if there is no scheduled activity be set to add a new record.

When the button is clicked on the main company form (on the on click event) 
this code runs:
Private Sub cmdCallBack_Click()
On Error GoTo Err_cmdCallBack_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    DoCmd.OpenForm "frmScheduleCallBack", , , , , , Me.CompanyID

Then on the other form that opens on the load event I have this code that 
runs:
This checks to see if there is a related record and display it if it finds 
one. If there is no related record it is ready to insert a new record.

I keep getting a datatype mismatch error on line 6 (below). The companyID in 
the company table is an autonumber.  I know that I can't compare a long 
integer to a string and get a match but how do I handle this problem??

1Private Sub Form_Load()
2Dim strCompanyID As String

3    If Not IsNull(Me.OpenArgs) Then
4        strCompanyID = Me.OpenArgs
5        With Me.RecordsetClone
6           .FindFirst "[CompanyID] = '" & strCompanyID & "'"
7            If .NoMatch Then
8                DoCmd.GoToRecord , , acNewRec
9                Me.txtCompanyID = strCompanyID
10            Else
11              Me.Bookmark = .Bookmark
12            End If
13        End With
14    End If

End Sub

0
Utf
12/6/2009 5:35:01 PM
access.formscoding 7493 articles. 0 followers. Follow

2 Replies
1048 Views

Similar Articles

[PageSpeed] 59

Jen,
    A subform, by itself... when associated to a main form via the 
Parent/Child
relationship... will do what you ask without any coding at all.
    Example:
    If I open (the sub could be just hidden) frmActivities for Smith & 
Company
(CompanyID = 1425) and there are no activity records associated with that
CompanyID, the subfrom will open with no records displayed... and sitting on
a New record, awaiting your data entry.
    From your description that's should do what you want...

>I am trying to link  to forms.
    That's what a main form and subform, related by some unique key value,
are for.
-- 
    hth
    Al Campagna
    Microsoft Access MVP
    http://home.comcast.net/~cccsolutions/index.html

    "Find a job that you love... and you'll never work a day in your life."

"Jen" <Jen@discussions.microsoft.com> wrote in message 
news:2E798981-1A1E-419E-A52A-05D06C50EA66@microsoft.com...
>I am trying to link  to forms.  I have a button on the main form
> (frmCompanies) that needs to open another form when a button is clicked. 
> The
> new form that opens is frmScheduledActivities. When it open it needs to 
> check
> to see if there is an existing record (scheduled activity) for the company
> and if there is no scheduled activity be set to add a new record.
>
> When the button is clicked on the main company form (on the on click 
> event)
> this code runs:
> Private Sub cmdCallBack_Click()
> On Error GoTo Err_cmdCallBack_Click
>
>    Dim stDocName As String
>    Dim stLinkCriteria As String
>    DoCmd.OpenForm "frmScheduleCallBack", , , , , , Me.CompanyID
>
> Then on the other form that opens on the load event I have this code that
> runs:
> This checks to see if there is a related record and display it if it finds
> one. If there is no related record it is ready to insert a new record.
>
> I keep getting a datatype mismatch error on line 6 (below). The companyID 
> in
> the company table is an autonumber.  I know that I can't compare a long
> integer to a string and get a match but how do I handle this problem??
>
> 1Private Sub Form_Load()
> 2Dim strCompanyID As String
>
> 3    If Not IsNull(Me.OpenArgs) Then
> 4        strCompanyID = Me.OpenArgs
> 5        With Me.RecordsetClone
> 6           .FindFirst "[CompanyID] = '" & strCompanyID & "'"
> 7            If .NoMatch Then
> 8                DoCmd.GoToRecord , , acNewRec
> 9                Me.txtCompanyID = strCompanyID
> 10            Else
> 11              Me.Bookmark = .Bookmark
> 12            End If
> 13        End With
> 14    End If
>
> End Sub
> 


0
Al
12/6/2009 6:51:27 PM
Jen -

Al's subform solution would be the way I would go.  So you know, your error 
comes from putting single quotes around the companyID field.  You indicated 
this is an AutoNumber field, which is a long integer, not text.

-- 
Daryl S


"Jen" wrote:

> I am trying to link  to forms.  I have a button on the main form 
> (frmCompanies) that needs to open another form when a button is clicked. The 
> new form that opens is frmScheduledActivities. When it open it needs to check 
> to see if there is an existing record (scheduled activity) for the company 
> and if there is no scheduled activity be set to add a new record.
> 
> When the button is clicked on the main company form (on the on click event) 
> this code runs:
> Private Sub cmdCallBack_Click()
> On Error GoTo Err_cmdCallBack_Click
> 
>     Dim stDocName As String
>     Dim stLinkCriteria As String
>     DoCmd.OpenForm "frmScheduleCallBack", , , , , , Me.CompanyID
> 
> Then on the other form that opens on the load event I have this code that 
> runs:
> This checks to see if there is a related record and display it if it finds 
> one. If there is no related record it is ready to insert a new record.
> 
> I keep getting a datatype mismatch error on line 6 (below). The companyID in 
> the company table is an autonumber.  I know that I can't compare a long 
> integer to a string and get a match but how do I handle this problem??
> 
> 1Private Sub Form_Load()
> 2Dim strCompanyID As String
> 
> 3    If Not IsNull(Me.OpenArgs) Then
> 4        strCompanyID = Me.OpenArgs
> 5        With Me.RecordsetClone
> 6           .FindFirst "[CompanyID] = '" & strCompanyID & "'"
> 7            If .NoMatch Then
> 8                DoCmd.GoToRecord , , acNewRec
> 9                Me.txtCompanyID = strCompanyID
> 10            Else
> 11              Me.Bookmark = .Bookmark
> 12            End If
> 13        End With
> 14    End If
> 
> End Sub
> 
0
Utf
12/7/2009 7:19:01 PM
Reply:

Similar Artilces:

Is It Possible To Pass Parameters to A Pass Through Query
My assumption is that's it's not. At work I use ODBC to connect to our oracle database with Access 2003. There are cases where using a pass through query runs much much faster and I then use it in a make table query to make a local table. In access you can use brackets [] to have it ask for input. May I assume there is no way to do anything like that in a pass through query? Create a PassThrough query and use code to assign the SQL to this query filtering it with a parameter, and then run it e.g Dim MyVariable As Integer MyVariable = InputBox("Please select a Number&quo...

Avoid drawing blank values
Hello, Can you tell me if there is a way to plot only non-blanked values from a table: F.e. if: X= 1,2,3,4 Y=10, ,10,10 (so no value for x=2) I want to obtain a continuous line going from the first point (1,10) to the third point (3,10) and then of course to (4,10). Thanks in advance for your help, Iv�n ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ On Mon, 10 Nov 2003 10:52:34 -0500, ivarela1 = <ivarela1.woqln@excelforum-nospam.com> wrote: > Can you t...

Pass multiple selected values from list box to table
How do I pass multiple selected values from a list box to a table? I've found code to use the values as criteria in a query but would now like to store the values in a table (at least temporarily) thanks in advance. jack Pass selected values from a list box to a table? I don't really think you want to do this. Can you describe more about what you are trying to accomplish? You just store raw data in a table. You don't store manipulated data in a table. Maybe you need a query to do what you want to do... -- Ryan--- If this information was helpful, please indi...

Require value for "regarding" in Outlook email promotion?
We want the Outlook client to require users to select a value (contact, account, etc.) for the "regarding" field when an email is promoted. If I customize the CRM “email” entity so that its “regardingobjectid” attribute is “Business Required”, will that do the trick? ...

Chart of frequences of values
Hello, How can I create chart of value�s frequences according to a frequenc table? (see attachement) Thanks a lot +------------------------------------------------------------------- |Filename: graph.JPG |Download: http://www.excelforum.com/attachment.php?postid=3691 +------------------------------------------------------------------- -- balcovj ----------------------------------------------------------------------- balcovja's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2623 View this thread: http://www....

Do not display Value label if value = zero
Hi I am putting together a pie chart, where values for some slices is 'zero'. The zero slice is not visible, but the label still appears '0%'. Is there any way of suppressing this label for the zero slice only (so the other slices still have value labels appearing) ? Many thanks for any help Format label, custom format: #;;; -- Best Regards, Luke M "LFNFan" <LFNFan@discussions.microsoft.com> wrote in message news:CC677569-1FB1-4108-8535-C5BDC6E1B825@microsoft.com... > Hi > > I am putting together a pie chart, where values ...

PivotTable buttons remembers old unactual values
I have discovered that buttons in the row area remembers old values not longer existing in the data. Ex: I have 4 persons with initials "aaa", "bbb", "ccc" and "ddd" I have the Initial button in the row area. When I click on the arrow of the "Initial"-button, it gives me the possibilities: "(Show all)", "aaa", "bbb", "ccc" and "ddd". If I change initial "ddd" to "xxx", refresh the pivot table and again click on the arrow of the "Initial"-button, it gives me the p...

Conditional values
I am looking for a formula that would accomplish the following: the entering of an alpha value in a cell would trigger populating the adjacent cell with a numeric value, i.e. entering 'Y' in cell A1 would automatically populate cell B1 with '1' (I use column B as a counter). Thank you. One way: B1: =IF(A1="Y",1,0) or, equivalently B1: =--(A1="Y") but depending on what you're doing, you can get a count of "Y"s in Column A using =COUNTIF(A:A,"Y") In article <E6DC0B82-515F-4488-AF0B-FE990B9BE714@microsoft.com&...

Uneditable Form
I set up a recurring email form with some code from slipstick systems used in conjection with task scheduler. It used to work fine. I've done something that changed this. I've changed and deleted some personal folders and I also attempted to edit the form. Anywhow I find now that I can find the form, but, when I select tools>forms>design a form and select it the form is sent rather that being brought up in a edit window. Does anyone have any ideas? Thanks in advance ...

Finding value
I have a user form where the user enters a site number. in the spreadsheet i have a range names "ValidSites". After the user enters a site number and clicks on a button, i would like to validate that that site appears in the ValidSites list. onclick event() if txtSiteNumber is found in Range(ValidSites) then msgbox("found") else msgbox("notfound") endif endsub what would be the code for the if statement? thanks in advance -- tkaplan ------------------------------------------------------------------------ tkaplan's Profile: http://www.excelforum.com/memb...

Data Dictionary with sample values
hi guys, I am going to create a data dictionary of our systems as I am sick of trying to find out what columns have been called in different tables. There is a hundred ways to do this but I am going to use INFORMATION_SCHEMA.COLUMNS to get the database, schema, table, column, type and length. So far so good. I also want the data dictionary to contain 'sample' data for each column so that you can see the types of values that are held in it. A query that looks something like this does the trick.. [code] SELECT TOP 5 * FROM ( SELECT Myfield as 'field',...

Form to query
Hello everybody, I have a question concerning the "Enter Parameter Value" window that opens when I run a query. I have asked this in the access.queries newsgroup but I couldn't get the answer. Is it possible to have that as a combobox so that a list of possibilities is shown? Another question has to do with the same query. This asks a date from and to (in the query criteria >[from] And [to]. I would like the selected period to be shown in the report. Is this possible (and if so... how can I achieve that)? Thanks for all the help you can give -- Lisa Save the Dogs Onlus...

How do I set the print range on a form. Regards
I've created a Timesheet on a form in Excel, but when I print, it only prints a third of the form Enter this into Excel help: Define or clear a print area on a worksheet This should give you a solution "Dave K" wrote: > I've created a Timesheet on a form in Excel, but when I print, it only prints > a third of the form In Excel 200, you would select the are to print, go to "File", "Print area", "Set print area". To make it easier and quicker to print in future, you can record a macro as you print the print area and att...

CMFCPropertyGridCtrl
Hi All, I have an MFC application with a TreeView and a CDockablePane Properties Window. When I select a tree item - I display its properties in the properties window. That works. But I don't know how to change the tree item properties when I change the values in the properties window. My problem is in getting the values from the properties grid. I tried to override EndEditItem method like this: BOOL CMyMFCPropertyGridCtrl::EndEditItem(BOOL bUpdateData) { CMFCPropertyGridProperty* currProperty = GetCurSel(); if(currProperty) { //I don't like this implementa...

Setting a value on a main form from a subform
All, Am I correct in assuming the way to set the value of a control on the main form from a subform is: Me.Parent.ControlName.Value = "XXX" Obviously it isn't because I continue to receive errors when I try to access the control. Thanks in advance. - CES CES wrote: > All, > Am I correct in assuming the way to set the value of a control on the > main form from a subform is: > > Me.Parent.ControlName.Value = "XXX" > > Obviously it isn't because I continue to receive errors when I try to > access the control. > > Thanks in advance...

Formula to determine row of hi value filtered column
Hi all Trying to see if its possible for a formula to return the row # of the highest or lowest visible value in an autofiltered range. Thanks Richard -- rgarber50 ------------------------------------------------------------------------ rgarber50's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=11350 View this thread: http://www.excelforum.com/showthread.php?threadid=401821 ...

How to pass an object from C++
Hello! We have a C# asp.net web application that is using a COM dll We use the tlbimp to be able to use the COM dll from C# asp.net web application The method InitRules shown below is located in the COM dll. It can be seen below the text Original. Method InitRules below is called from C# but we want to pass an object of type Handle_DS in addition to all the other parameters. You can see the modified InitRules below marked Modified Note the object of type Handle_DS is a C++ object that is created from C# asp.net application and pass into the InitRules I have also copied the whole idl fil...

Filter Report by Form
I have a report with both text, date and Yes/No fields and I am trying to filter the report data with a pop-up form. I have fields I want to filter the data by. I have code that works with 'Text' fields; it is For intCounter = 1 To 5 If Me("Filter" & intCounter) <> "" Then strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And " End If If i take out ...

Preventing user altering cell except to delete the value.
Is there a way to stop a user altering the value in a cell but still allow him to delete the value there-in? Rob One way: Put this event macro in your worksheet code module (right-click on the worksheet tab and choose View Code): Private Sub Worksheet_Change(ByVal Target As Excel.Range) Const cVALUE As Double = 100 With Target If .Address(False, False) = "A1" Then _ If Not IsEmpty(.Value) Then .Value = cVALUE End With End Sub Change cVALUE and the address of your cell to suit. In article <uCkCXD4uDHA.1680@TK2MSFT...

Checking a forms fields for null
Hi All, I can think of a few ways to accomplish this, but would like to know of a better way. just like when you fill out forms on the web if the field is mandatory it pops up a msg say somthing like "This field isn't optional" if it is left blank. What is the best way to do this in access on a form? I'm using now: if ISNull(myFeild1) then msgbox"Please fill in myFeild1" end if If ISNull(myFeild2) then msgbox"Please fill in myFeild2" end if if ISNull(myFeild3) then msgbox"Please fill in myFeild3" end if I use s...

Making form using Excell Help ASAP!
I've made a form. This needs to be filled out online. I can freeze cells so the user cannot mess with them, but how do I form lines.? Say, a line above 'Customer Name' in order to answer that question. This is really getting to me b/c it seems like it should be so easy... Hi Amanda not really sure what you're after but if you click in a cell and choose format / cells and click on the border tab and then the top line icon does this give you what you want? Cheers JulieD "~Amanda~" <~Amanda~@discussions.microsoft.com> wrote in message news:26819D...

100% Passing Guaranteed in All I.T. Exams/Certifications at 1st Attempt Hi Friends, To pass all types of I.T Exams/Certifications with mind blowing results in 1st attempt just visit http://www.itreal
100% Passing Guaranteed in All I.T. Exams/Certifications at 1st Attempt Hi Friends, To pass all types of I.T Exams/Certifications with mind blowing results in 1st attempt just visit http://www.itrealexams.com/ and get real time Q&As, Brain Dumps, Real Exams, Study material, E-Books, Video Exams and Labs for your all type of I.T Certification Exams. ...

IT CertificationzzzZ.....100% GUARANTEED PASS.......!!!@!!!
IT CertificationzzzZ.....100% GUARANTEED PASS.......!!!@!!! Hi guys, If you are serious about your professional career and pass IT Certification exam in first attempt then Visit http://www.FreeExamKing.com and get latest Questions And Answers Dumps for Microsoft, Oracle, Cisco, CompTIA and many more, i have used and found it very helpful. ...

need an error msge when I attempt to enter a duplicate value in a
I am entering unique serial no. in col A. Can I set up a rule which will not allow a duplicate serial no. entry into another cell? See http://cpearson.com/excel/NoDupEntry.htm In article <FFEF019B-E20C-4177-856A-8D8BD0F0698F@microsoft.com>, "pg23673" <pg23673@discussions.microsoft.com> wrote: > I am entering unique serial no. in col A. Can I set up a rule which will not > allow a duplicate serial no. entry into another cell? Check out the validation in the Data section. select the area of interest (A:A) <data><validation><Settings><C...

Form feeding a table problem
I am a newer user of Access and inherited a database from a person no longer with the company. I am using a form to input invoice amounts into an invoice table. The form uses a parameter query to ask for invoice number. When the form opens, I have it pulling customer info from a customer table, which it displays on the form. I then enter more invoice info. When I look at the invoice table after I close the form, the info I typed (invoice update) is there, but the customer info that is automatically pulled doesn't load from the customer table to the invoice table. How can I g...