NILKAMAL


hi!

can some one help me for this

i want to creat search form as below

1) option button - fielda

2) option button- fieldb

3) option button - field c

here is i place one textbox for user can put value and search button to search

and if record found then go to my my form with this value

thanks




Re: search with option

dni


You may put in click method of each option button to enable the textbox(initially disabled);
(so if you choose 1,you will have thisform.optiongroup.option1.value = 1.)
In method Valid of textbox, for example, you may put the code:

do yourform with thisform.optiongroup.option1.value = 1,thisform.textbox value

In method init or load from form yourform you should insert:

PARAMETERS chosenoption,textboxcontent







Re: search with option

NILKAMAL

sorry i am new in vfp

how to enable to the textbox

or if you cand code snipp

thanks






Re: search with option

dni

You may choose in property window for textbox, Enabled = .F. To enable you may use:

thisform.texbox.Enabled = .T.






Re: search with option

NILKAMAL

hi!

thanks for your reply but i still have problem

one i want to create search form as below

customer id : TEXTBOX

driver lic # : TEXTBOX

searchbutton cancel

now if user put any of textbox value in textbox and click on searchbutton it search from my custome.dbf and if found then open a another form (customer.scx ) with value from search form and hide a search form

help me on this problem

thanks





Re: search with option

dni

You may put in click on search button something like:

Code Snippet

IF FOUND() =.T.

DO FORM CUSTOMER WITH thisform.TEXTBOX1.Value,thisform.TEXTBOX2.Value

thisform.Release

ENDIF

*in form CUSTOMER init method you may put:
PARAMETERS var1,var2 && var1 will be thisform.TEXTBOX1.Value,var2 = will be thisform.TEXTBOX2.Value






Re: search with option

Cindy Winegarden

Hi Nikamal,

I created two forms that are something like you have in mind. Then I opened them in the Class Browser (you may not have known that this was possible) and here's the code I got:

Code Snippet

PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


**************************************************
*-- Form: form1 (d:\documents\visual foxpro\testsearch.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 06/06/07 02:25:06 PM
*
DEFINE CLASS form1 AS form


DoCreate = .T.
Caption = "Form1"
Name = "Form1"


ADD OBJECT command1 AS commandbutton WITH ;
Top = 156, ;
Left = 48, ;
Height = 37, ;
Width = 145, ;
Caption = "Command1", ;
Name = "Command1"


ADD OBJECT text1 AS textbox WITH ;
Height = 25, ;
Left = 36, ;
Top = 84, ;
Width = 109, ;
Name = "Text1"


ADD OBJECT text2 AS textbox WITH ;
Height = 25, ;
Left = 168, ;
Top = 84, ;
Width = 109, ;
Name = "Text2"


PROCEDURE command1.Click
Do Form TestFound With ThisForm.Text1.Value, ThisForm.Text2.Value
ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************


Code Snippet

PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


**************************************************
*-- Form: form1 (d:\documents\visual foxpro\testfound.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 06/06/07 02:29:02 PM
*
DEFINE CLASS form1 AS form


DoCreate = .T.
Caption = "Form1"
parameter1 = .F.
parameter2 = .F.
Name = "Form1"


ADD OBJECT text1 AS textbox WITH ;
ControlSource = "ThisForm.Parameter1", ;
Height = 37, ;
Left = 48, ;
Top = 60, ;
Width = 109, ;
Name = "Text1"


ADD OBJECT text2 AS textbox WITH ;
ControlSource = "ThisForm.Parameter2", ;
Height = 37, ;
Left = 48, ;
Top = 120, ;
Width = 109, ;
Name = "Text2"


PROCEDURE Init
Parameters Parm1, Parm2

*-- Set form properties.
*-- Form properties are better than public variables.
With ThisForm
.Parameter1 = Parm1
.Parameter2 = Parm2
EndWith
ENDPROC


PROCEDURE text1.Click
This.Value = ThisForm.Parameter1
ENDPROC


PROCEDURE text2.Click
*-- This.Value = ThisForm.Parameter2
ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

You can see in TestSearch that I've added two textboxes and in the Click of the button I call the TestFound form and pass it the two parameters. In the TestFound form I've added two form properties and set the ControlSource property of each one to the appropriate form property. In the Init of the form I've got the Parameters statement that "catches" the parameters that TestSearch "threw" at it.

A note about Form parameters - Unless variables are Public they can't be seen everywhere in the form. But Public variables aren't a good idea because you might accidentally change one's value somewhere else in your program if you've happened to use the same name again. The preferred way to have a "variable" visible (in scope) everywhere in a form is to create a form property (from the menu: Form > New Property) and then give that property a value in the appropriate place.






Re: search with option

NILKAMAL

hi!

i asked this question before but i still dont understand the replies that were given so please can someone try to explain with codesnipp

table name : customer

field name : cust_id - index

first name , last name etc....

form name : customerdetail

now i want to create search form as below :

customer last name : textbox1

first name : textbox2

searchcommand clearcommand

now when user put some value in any textbox and click searchbutton , if found open the customerdetail form with that value

so please can anybody help me for search button code and my customerdetail form init code

thanks





Re: search with option

dni

In form customerdetail:

-Create a button SEARCH and in
click method:

Code Snippet
DO FORM search

In form search:

-In searchcommand button click method:

Code Snippet
select customer
go top
seek thisform.textbox2.value + thisform.textbox1.value && depending how is you index made
if found() =.T.
customerdetail.refresh
thisform.release
else
* you may put a message "not found"
endif






Re: search with option

Naomi Nosonovsky

Hi,

Let's assume, that you have at least two indexes in your table:

CustID (candidate or primary)

Customer with the expression of upper(LastName+FirstName)

In the search form you put two textboxes:

txtLastName and txtFirstName close together

bellow you put

cmdSearch and cmdClear buttons.

First let's deal with the clear button. Do you want this button to clear the user's input in the textboxes

If yes, then simply put

Code Snippet
store "" to thisform.txtLastName.value, thisform.txtFirstName.value

Now, for the Search button you may either try to use seek (the Customer table should be opened when) or select-SQL.

Let's assume you want to use SEEK.

Then the code would be something like this:

Code Snippet

if empty(thisform.txtLastName.value)

=messagebox("You must provide the Customer's last name for the search",0,"Enter Last Name")

thisform.txtLastName.SetFocus()

return .f.

endif

** If you want to force them also always use first name, then you would have to put similar code for the first name

if not used('Customer') && The customer table is not yet used, let's try to open it

use Customer in 0 alias Customer shared && This may fail, so I usually wrap this in try/catch block

endif

local lcLastName, lcFirstName, lcSetExact

lcSetExact = set('exact')

set exact off && we may need this for partial search

lcLastName = padr(thisform.txtLastName.value,30) && This number should be the field length of the Last Name in your table

lcFirsttName = alltrim(thisform.txtFirstName.value)

if seek(upper(m.lcLastName + m.lcFirstName,'Customer','Customer')

do form CustomerDetail with Customer.CustID

else

** We don't have this customer

=messagebox('Customer ' + alltrim(m.lcLastName) + " is not found. Try again",0,"Not found")

endif

if m.lcSetExact = 'ON'

set exact on

endif

Your CustomerDetail form may accept Customer ID as a parameter.





Re: search with option

NILKAMAL

thanks for reply

i did as you say but i received error " to many arguments" for this line

if seek(upper(m.lcLastName + m.lcFirstName,'Customer','Customer')

thanks





Re: search with option

Naomi Nosonovsky

I'm sorry, I made a typo. It should be

Code Snippet

if seek(upper(m.lcLastName + m.lcFirstName),'Customer','Customer')





Re: search with option

NILKAMAL

thanks for help but still i receive error

"operator/operand type mismatch"

thanks





Re: search with option

Naomi Nosonovsky

Would you please post the exact line of code with the problem Did you try to examine variables in the Debugger

Perhaps, one of the variables was named incorrectly, thus now it is evaluated to .f.

Thanks.

UPDATE. I found another typo in my sample, sorry:

lcFirsttName = alltrim(thisform.txtFirstName.value)

Should have been

lcFirstName = alltrim(thisform.txtFirstName.value)





Re: search with option

NILKAMAL

thanks for your reply and help but i thing problem is in my table index , now i receive error index tag not found

my table set as below

field index

cust_id - primary

first_name - upper(first_name)

last_name - upper(last_name)

plese let me know i have to with index or any code in my search button for index on

thanks