473,382 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Need to open one of two forms by clicking into a third form's field

I have three forms: (1) A list of all CPARs in my system. Some are open, some are closed. The open ones are query-limited and show only in this form: "CPARsForm". The closed CPARs are query-limited and show only in this form: "CPARsForm_Closed".

When I open the list, I would like to be able to click the CPAR number (or ID) and have code find the right form to open and open to the right CPAR (the one I clicked on).

Here's my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ID_Click()
  2. On Error GoTo Errhandler
  3.  
  4.     With CodeContextObject
  5.        DoCmd.Echo True, ""
  6.         If (IsNull(.ClosedDate)) Then
  7.             DoCmd.OpenForm "CPARSForm", , "", ""
  8.  
  9.             Dim strCriteria As String
  10.             Dim rs As DAO.Recordset
  11.  
  12.             strCriteria = "[ID] = " & Me.[ID]
  13.             Set rs = [Forms]![CPARsForm].RecordsetClone
  14.  
  15.             rs.FindFirst strCriteria
  16.  
  17.             If rs.NoMatch Then
  18.                 MsgBox "No match found"
  19.             Else
  20.                 [Forms]![CPARsForm].Bookmark = rs.Bookmark
  21.                 [Forms]![CPARsForm].SetFocus
  22.  
  23.             End If
  24.  
  25.             rs.Close
  26.             Set rs = Nothing
  27.         Else
  28.             DoCmd.OpenForm "CPARsForm_Closed", , "", ""
  29.  
  30.             Dim strCriteria2 As String
  31.             Dim rs2 As DAO.Recordset
  32.  
  33.             strCriteria2 = "[ID] = " & Me.[ID]
  34.             Set rs2 = [Forms]![CPARsForm_Closed].RecordsetClone
  35.  
  36.             rs2.FindFirst strCriteria2
  37.  
  38.             If rs2.NoMatch Then
  39.                 MsgBox "No match found"
  40.             Else
  41.                 [Forms]![CPARsForm_Closed].Bookmark = rs2.Bookmark
  42.                 [Forms]![CPARsForm_Closed].SetFocus
  43.  
  44.             End If
  45.  
  46.             rs2.Close
  47.             Set rs2 = Nothing
  48.     End If
  49. End With
  50. Exit_ID_Click:
  51. Exit Sub
  52.  
  53. Errhandler:
  54.     MsgBox Err.Description
  55.     Resume Exit_ID_Click
  56. End Sub
  57.  
Can someone please tell me why it only gives me the No Match found message and doesn't open the correct form.
Thanks
Oct 20 '14 #1
4 1075
zmbd
5,501 Expert Mod 4TB
rc17wagg:
Insert the command stop at line 3

Click into your event to start the code.

[F8] to step thru the code. Pay attention to the variable values by either hovering over them or <ctrl><g> and then type ?variablename[enter] to return the value.

Also, please very carefully follow the trouble shooting steps/section in this article: [*] > Before Posting (VBA or SQL) Code
Oct 20 '14 #2
Thanks for your help but it is rather obscure to me. I'm not well-versed in VBA - just enough to get into trouble. All I'm trying to do is open a different form based on whether or not a record is closed. If it is closed, I want to open the CPARsForm_Closed. If open, the CPARsForm.

Another clue might be that it can't find a match when the event executes.
Oct 21 '14 #3
twinnyfo
3,653 Expert Mod 2GB
If your two forms display the same information, why not just use one form? Then, just filter the form by either open CPARs or Closed CPARs. Then your code simply looks like this:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "CPARSForm", , , "ID = " & Me.ID
Your code seems overly complex for simply opening a form to a set record.
Oct 21 '14 #4
Thanks! I'll try that instead. Usually the simplest answer is the best. I appreciate your response.
Oct 21 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Danny | last post by:
HI, I am trying to do a group by such as this: "select code, colors from productdb group by code, colors" I need to sort on the key field, but cannot throw in the 'ordre by key', because i...
2
by: Big John | last post by:
Is it possible to open an input window by selecting a lookup criteria from a field in a table eg if a lookup field in a table has choice A, B, C, and one selects "B", can this be used to open a...
4
by: Bilo | last post by:
I have a Windows Forms Class MainGUI I have declared MainGUI maingui; public System.ComponentModel.Container components = new Container(); in the Class I call another class MediaDriver with...
2
by: Darin Browne | last post by:
My company is moving from PowerBuilder to .NET and we are split on if we should use web forms or win forms for our LAN apps. The developers want to do web forms but management is leaning towards win...
6
by: lphan | last post by:
Hi there, The project that I'm working on is a securty piece of n-tier applications which try to authenticate a user. The login page, either a web form or windows form, calls a web service (thin...
2
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having...
2
by: André | last post by:
Hi, is it possible to trigger an action (e.g. make visible a button) when clicking in a particular field of a detailsview? I think is it, but how? I tried it on several ways, but no succes....
3
by: John.Forr | last post by:
I'm creating a data-entry form for 3 tables. There is a one-to-many relationship between table1 and table2 and a 2nd one-to-many between table2 and table3. What I would like to do is have the...
13
by: deville75 | last post by:
Hi, I'm somewhat new to MS Access and I'm having trouble with displaying two forms. Firstly my program is going to use a search button to search through several different Tables. The Search Form...
1
by: Bob Simon | last post by:
I'm trying to find what what forms and reports use a particular field, because I'm replacing it with another field. How can I search forms and reports for a field name?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.