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

Search Form to Search for Value in another Form

17
Hello ! Hope someone might be able to help me with this one. I run Access2000 on XP.

I have a form : frmONE- which contains a txt field: ctrCTN from my table/database. The values in ctrCTN are unique. Next to this field is a cmdFIND button

frmONE is open and the active window.
I want to search for values in ctrCTN, and go to the record which contains that value. I do not want to use a cmdButton with in-built Access Find procedure to FindRecord. And I don’t wasn’t to use a ComboBox as the field being searched will contain 25000+ records. I can utilize an unbound text box place on frmONE (which I found here http://www.databasedev.co.uk/text_search.html) but my frmONE is pretty full and I would prefer to use a second pop-up form, frmTWO.

ie:
FrmTWO: is a popup modal form, with:
an unbound textbox, txtEntry,
a cmdSearch button. whose On_Click Event procedure runs the search
a cmdClose button which closes the frmTWO

1) User on active frmONE clicks the cmdFIND button
2) FrmTWO opens, and User is asked to enter value to look for, in txtEntry.

IF: User decides at this point not to search after all:
3) User clicks cmdCLOSE, and closes the frmTWO., and focus returns to returns to frmONE, and say to fldCTN.

Otherwise,
User enters a value into txtEntry (on frmTWO)
4) The code will take the value entered and look for it in frmONE, in ctrCTN

IF: the sought value is found on frmONE, in ctrCTN, then the that record on frmONE receives focus, frmTWO will close and a message box will pop up saying “Record Found” (OK).

ELSE, IF The Value is not found, the focus remains on FrmTWO in txtEntry, and a message Box pops up saying “Record is not found, Please try again” (OK).

User is then left on frmTWO, and can either perform another search , or close the form (cmdClose) and return to frmONE.

I can play with the code (found for the textbox search link above,) to the point, where if a valid value is entered on frmTWO, the frmONE record with that value is retrieved and focus is in ctrCTN, and frmTWO closes ... Where I’m stuck is the coding for if the search value is not found, and I want to continue action on FrmTWO (ie another search, or close it).

Many thanks for your help!
AMBLY
Jun 4 '07 #1
9 2771
MMcCarthy
14,534 Expert Mod 8TB
Don't have frmONE open and Active. Create frmTWO to be a search form that will open frmONE to the specific record only

On frmTWO have an unbound textbox called txtctrCTN and a button called cmdFind

Put this code behind the cmdFind Button
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdFind_Click()
  3.  
  4.     DoCmd.OpenForm "frmONE", , , "[ctrCTN]='" & Me.txtctrCTN & "'"
  5.     DoCmd.Close acForm, "frmTWO"
  6.  
  7. End Sub
  8.  
This will open frmONE to the spedified record.
Jun 4 '07 #2
AMBLY
17
Thankyou for the reply and sorry for my late acknowledgement - I thought I would get an auto-email advising I had a reply to my question, but I didn't (unless I deleted it in error!!)......

Out of neccessity, the user is already in FRM1 (which has restricted password-only entry) when s/he needs to perform the search, so unless I've missed the plot (not unimaginable!) I think this code will not do what I want, unless I add an enter-password line to it, which would be a bit OTT (or perhaps a line to deactivate FRM1 while action is performed on FRM2 ???) ,,,,,but this code will certainly be useful to me in other areas.

Meantime, I have found a work-around - utilising show and hide methods of txt and cmd etc, which works well in it's environment.

Thanks again!
AMBLY
Jun 9 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thankyou for the reply and sorry for my late acknowledgement - I thought I would get an auto-email advising I had a reply to my question, but I didn't (unless I deleted it in error!!)......

Out of neccessity, the user is already in FRM1 (which has restricted password-only entry) when s/he needs to perform the search, so unless I've missed the plot (not unimaginable!) I think this code will not do what I want, unless I add an enter-password line to it, which would be a bit OTT (or perhaps a line to deactivate FRM1 while action is performed on FRM2 ???) ,,,,,but this code will certainly be useful to me in other areas.

Meantime, I have found a work-around - utilising show and hide methods of txt and cmd etc, which works well in it's environment.

Thanks again!
AMBLY
You're welcome
Jun 9 '07 #4
AMBLY
17
Hi Mary
I hope you can help me again :-)

Just rethinking the whole thing, based on your previous advice - I am now opening FORM1 to a specific record (via a search in it's field named: CTN) by having Users enter search criteria into a FORM2 unbound text box.

FORM2 TxtBox is called: txtCtrCTN)......I put a cmdButton called cmdFindCTN beside it via CommondBox Wizard. The resulting unadulterated code behind the button is as follows

--------------------------------------------------
Private Sub cmdFindCTN_Click()
On Error GoTo Err_cmdFindCTN_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FORM1"

stLinkCriteria = "[CTN]=" & Me![txtCtrCTN]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdFindCTN_Click:
Exit Sub

Err_cmdFindCTN_Click:
MsgBox Err.Description
Resume Exit_cmdFindCTN_Click

End Sub
--------------------------------------------------------

Now, this works fine, BUT only if the User has searched for a valid CTN number on FORM1.

How (where?) do I amend the code to handle the situation where User has tried to find a CTN that does not exist....?? ie: if a match is not found, a msg box like:

MsgBox "Match Not Found For: " & stLinkCriteria & " - Please Try Again.", vbInformation, "Invalid CTN number!"

My inexperience with coding is showing! Hope you can help

Regards
AMBLY
Jun 12 '07 #5
AMBLY
17
I should also add....as the code stands at present:

If user has tried to find a CTN on FORM1 which does not exist, FORM1 still does open, but none of the fields are visible. So any code amendment, would have to cancel opening of FORM1, and just leave User on FORM2 with the desired msg box popping up.

Also, if a match is found, I want FORM2 to close when FORM1 is opened

Thanks!
AMBLY
Jun 12 '07 #6
JConsulting
603 Expert 512MB
I should also add....as the code stands at present:

If user has tried to find a CTN on FORM1 which does not exist, FORM1 still does open, but none of the fields are visible. So any code amendment, would have to cancel opening of FORM1, and just leave User on FORM2 with the desired msg box popping up.

Also, if a match is found, I want FORM2 to close when FORM1 is opened

Thanks!
AMBLY

easiest...

do a DCount using that CTN value...assuming it's in a table somewhere.

if DCount("*","thattable","CNT = " & me.CNT) then '<---add ticks ' ' if CNT is text
msgbox"Not found, try again"
exit sub
else
do your form open thing
end if

basically if the count returns 0, it's evaluated as false...kind of a shortcut thing.

let me know if this all makes sense to you
J
Jun 13 '07 #7
AMBLY
17
Hi J
Thanks for looking !

So, yes I can sort of understand...but sorry, I still need a bit of coaching as to where to put things!

CTN is a Primary Key/AutoNumber field in table named tblCOMPLIANCE.
It's format is 000. FRM2, the search form, has the Unbound Text Box also set as format 000.

So, on my Search FRM2, behind the Search button named cmdFindCTN, I put this code - which I'm sure I've got muddled with,

Private Sub cmdFindCTN_Click()
1. Dim stDocName As String
2. Dim stLinkCriteria As String

3. stDocName = "frmONE"

4. stLinkCriteria = "[CTN]=" & Me![txtCtrCTN]
' txtCtrCTN is the SearchBox on FRM2

'Add J's code here:

5. If DCount("*", "tblCOMPLIANCE", "CTN = " & Me.CTN) Then '<---no ticks ' ' because CTN is not a text fld
6. MsgBox "Not found, try again"
7. Exit Sub
8. Else
9. DoCmd.OpenForm stDocName, , , stLinkCriteria
10. End If

End Sub

What I get, if I try find a valid CTN number on FRM1 with this code , is Compile error - Method or Data not found on line 5. in the & Me.CTN), highlighting the .CTN bit.

I tried changing & Me.CTN), to & Me.txtCtrCTN), - ie: in my logic comparing table to Search Box (???) , but then what happens:
If I try find a valid number (is on table) I get the Line 6. msg Box.
If I try find an invalid number (is not on table) It opens FRM1 - but of course, there is no valid record match, so I just get the form design including Cmd butons that happen to be on it.... and no visible fields...

I'm sure I've done something daft!?

Cheers
AMBLY
Jun 13 '07 #8
AMBLY
17
Also - not sure if this makes a difference..

Whilst fld: CTN is on tbleCOMPLIANCE, the FRM1 (where we are trying to locate a valid CTN via this FRM2 SearchBox) is created from a Query based on tblCOMPLIANCE and one other tbl....?

Cheers
AMBLY
Jun 13 '07 #9
130975
18
Hi,
I have the same problem. So I was trying to adjust my coding. Is your problem Solved? If yes Please write the complete solution.
Jul 17 '07 #10

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

Similar topics

1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
3
by: suek | last post by:
I have a table with over 4000 records to search upon, and the users don't like a combo box. So what I have been trying to do for the last twelve hours is do some code to get a text box to search. ...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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
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...

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.