473,320 Members | 1,900 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,320 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 1073
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?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.