473,385 Members | 1,782 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,385 software developers and data experts.

Open a form based on a value associated with text in a field

Ok, I have several different record types in a table which are differentiated by a field which assigns what each record belongs to. There are "equip" records and "eng" records.

On a form that displays a filename ("frm_hardcopies"), the field is called "Filename". The equip and eng files are maintained in 2 seperate forms, but both contain the filename value. If I double click on frm_hardcopies.Filename, would it be able to look at tbl_documents.Path (which is the linked filename field), and if that record's "doc_filter" value is "equip", it would open frm_equip_docs, or if the "doc_filter" value is "eng" it would open frm_eng_drawings and go to the appropriate record? The "doc_filter" field is only in tbl_documents, not in tbl_hardcopies.

This is the only code I have so far, which just opens 1 of the forms based on the filename. It doesnt look at the filter criteria yet.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Filename_DblClick(Cancel As Integer)
  2.  
  3. On Error GoTo Err_Path_Click
  4.  
  5.     Dim stDocName As String
  6.     Dim stLinkCriteria As String
  7.     stLinkCriteria = "Path = '" & Me.Filename & "'" 'Assuming that the value you want is in the Path field
  8.  
  9.  
  10.     stDocName = "frm_equip_docs"
  11.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  12.  
  13.  
  14. Exit_Path_Click:
  15.     Exit Sub
  16.  
  17. Err_Path_Click:
  18.     MsgBox Err.Description
  19.     Resume Exit_Path_Click
  20.  
  21. End Sub
Oct 7 '11 #1
8 4330
NeoPa
32,556 Expert Mod 16PB
I expect it can be done but it's so hard to know without a much better idea of what you're working with. I suggest some Meta Data would help this along. A full description of the data structure and form structure you're working within.

Here is an example of the sort of thing I'm talking about :
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. StudentID       AutoNumber    PK
  3. Family          String        FK
  4. Name            String
  5. University      String        FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Oct 7 '11 #2
ok, frm_hardcopies.Filename contains the value that will call to and load either frm_equip_docs.Path OR frm_eng_drawings.Path based on the record value of tbl_documents.Path's corresponding value in the field "doc_filter". If doc_filter = equip Then it would open frm_equip_docs based on
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "Path = '" & Me.Filename & "'"
, ELSEIF doc_filter = eng Then it would open frm_eng_drawings based on
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "Path = '" & Me.Filename & "'"
Oct 7 '11 #3
NeoPa
32,556 Expert Mod 16PB
So, if it's one way it does one thing, and if it's the other it does exactly the same thing?

I'm not sure this helps much to clarify the situation. I was expecting a clarification of the filtering - hence the requirement for meta data (which is still outstanding btw).
Oct 7 '11 #4
no, if its 1 way it should open formA. if if the other way it should open FormB. the value in tbl_documents.doc_filter would tell it which form to open
Oct 7 '11 #5
NeoPa
32,556 Expert Mod 16PB
Now I'm really confused. Are you telling me someting is different between the two lines of code posted in post #3, or am I to understand your way of clarifying the situation was to illustrate only the part where they are similar? Twice?

Still no meta data. Still miles from clarity.
Oct 7 '11 #6
nevermind, I got it. I created a hidden dropdown linked back to tbl_documents that pulled up the Path and doc_filter info. The control source for the dropdown is [Forms]![frm_hardcopies]![Filename]. Then, based on the value in the 2nd column of the dropdown (doc_filter), the DblClick event opens the form accordingly. It works so far, however when I go to the next record on frm_hardcopies and try clicking on the field again, nothing happens. I have to figure out how to refresh the event or something so it works every time I use it

Expand|Select|Wrap|Line Numbers
  1. Private Sub Filename_DblClick(Cancel As Integer)
  2.  
  3. On Error GoTo Err_Path_Click
  4.  
  5.     Dim stDocName As String
  6.     Dim stLinkCriteria As String
  7.     stLinkCriteria = "Path = '" & Me.Filename & "'" 'Assuming that the value you want is in the Path field
  8.  
  9. If filt_form.Column(1) = "equip" Then
  10.  
  11.     stDocName = "frm_equip_docs"
  12.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  13.  
  14. ElseIf filt_form.Column(1) = "eng" Then
  15.  
  16.     stDocName = "frm_eng_drawings"
  17.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  18.  
  19. End If
  20.  
  21.  
  22. Exit_Path_Click:
  23.     Exit Sub
  24.  
  25. Err_Path_Click:
  26.     MsgBox Err.Description
  27.     Resume Exit_Path_Click
  28.  
  29. End Sub
Oct 7 '11 #7
got that too. I added Refresh before setting Dim in the VBA
Oct 7 '11 #8
NeoPa
32,556 Expert Mod 16PB
Congratulations then I guess. I'm pleased you managed to find a solution, but I worry you won't get the best of help in future unless you work out how to ask your questions more clearly. We'll leave that for now though as you got a solution instead. Well done.
Oct 7 '11 #9

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

Similar topics

1
by: Dom Nicholas | last post by:
Hi, I have a table (inside a form) that is dynamically created ie the user can add / remove rows dynamically. Each table row has 4 columns : a selection pull down list a text field for...
4
by: steph | last post by:
Hello, I've got a text field in an access form (Microsoft Access 2002, SP3), that the user has to fill out. Now I don't want the user to leave this field (and this record) until he has filled...
0
by: Pupkin | last post by:
Hi, Is there any kind of built-in control for a dropdownlist with a contextual text field option? For example: Choose one: This
1
by: starke1120 | last post by:
Is there a way to open a form based on query type.. Example.. If a certain query result is 1 then open the form to this result.. If the query results are NULL or 0 results, then open open for...
6
by: Markus_989 | last post by:
I have a LOANS table that has a list of loan details for different borrowers. I have a main switchboard with a LOANSELECT combo box (that displays a list of borrower last names and loan numbers)....
1
by: Kevin | last post by:
The menu form has two options, one to create a new estimate, the second to open an existing estimate. Under option two is a list box containing all of the estimates. There are several different...
10
by: Beatrice | last post by:
I need to open a form selecting all data from a previous form i.e: Form 1) combo box 1 named "cboYearSelect" displayed as "Year" based on qry QryYearList ( only one field "Year") ...
18
kcdoell
by: kcdoell | last post by:
Hello: I have two fields on a table that is displayed on my continous form. GWP = Number Binding Percentage = Text (a value list of 25%, 50%, 90% & 100%) I have a unbound text box that I...
3
by: Mihail | last post by:
I have some global variables. I use this variables to open a form based on a query with parameters. Now I use the On Load event to prepare an SQL string which include values of the global...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.