?
Solved

Combo Box question

Posted on 2012-09-06
12
Medium Priority
?
944 Views
Last Modified: 2012-09-12
Have a problem with a combo box, which I assume I am not setting up correctly.

For the first time I have a combo box which can either have no selection or a selection not currently in a table.  I want to be able to enter text, and if the box cannot find a match just save the value in the current table.

However, the table is setup to allow lookups from other table and select them, if desired.  I name the Rowsource table (Payers) and the RowSourceType set to 6-fields.

The problem is that every time I hand enter a value that does not exist in the table, NO value is saved in the Checks table.  If I use a code known Payers, no problem.  A check in the VALID method shows the hand entered data is not said if no reference in Payers.

Anyone have an idea how to save the data in the one table if it does not exist in the other.  I plan to give the OPTION to save the data if the customer desires.

Frank
0
Comment
Question by:fmoore0001
  • 7
  • 4
12 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38374902
SELECT key FROM table1 WHERE key NOT IN (SELECT key FROM table2) INTO CURSOR newkeys
SELECT table2
APPEND FROM DBF('newkeys')
USE IN newkeys
0
 

Author Comment

by:fmoore0001
ID: 38374910
CaptainCyril,

That is not the problem.  How to I make the combo drop down box accept a value NOT FOUND in the associated table.  I want to be able to select from the table, or hand enter a value not found in the table, and have it save.

Frank
0
 
LVL 27

Assisted Solution

by:CaptainCyril
CaptainCyril earned 1000 total points
ID: 38374929
I don't usually have the combobox linked with tables directly, however I try to locate the value. If not found then add it.

I usually build the comboboxes with This.AddItem() for various reasons.

Valid Event()
IF NOT SEEK(This.Value, 'table', 'index')
    This.AddItem(This.Value)
    INSERT INTO table (key) VALUES (This.Value)
ENDIF
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:fmoore0001
ID: 38374938
That is the problem.   By the time in VALID the hand entered value is LOST if not found, so I have to deal with a empty VALUE aleady.  I have no THIS.VALUE to work with!!

does any property store the entered value BEFORE the VALID method.

Frank
0
 
LVL 43

Assisted Solution

by:pcelba
pcelba earned 1000 total points
ID: 38375284
You may use Combo.DisplayValue it contains the typed text.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38375450
I am sorry. I meant This.Text not This.Value
0
 

Author Comment

by:fmoore0001
ID: 38377780
Guys, I am halfway there.  The use of THIS.displayvalue DID allow me to set and save the field to the table, but the the display still blanks.

 Checks.payer_code is the ControlSource

I have the RECORDSOURCE set to PayersLookup with a field list.  The actual store is done in Checks and the field list.

In the data environment PayersLookup is a lookup table only.  Checks is relationalized to Payers.  But, there is not  record in Payers

RECORDSOURCETYPE is set to 6

* Load Code
LOCAL cOldValue

* WAIT WINDOW "GOT HERE"

* WAIT WINDOW "This.displayvalue: " + THIS.DisplayValue

m.cOldValue = THIS.displayvalue
REPLACE Checks.payer_code WITH m.cOldValue
THIS.Value = m.cOldValue

* WAIT WINDOW "This.value: " + THIS.value

* REPLACE Checks.payer_code WITH THIS.Value

* WAIT WINDOW "Checks.payer_code: " + Checks.payer_code

IF NOT EMPTY(THIS.Value)
      IF SEEK(UPPER(Checks.payer_code), "PayersLookup", "payer_code")
            REPLACE Checks.payer_id WITH PayersLookup.payer_id
            REPLACE Checks.payer_code WITH PayersLookup.payer_code
            REPLACE Checks.payer1 WITH PayersLookup.payer1
            REPLACE Checks.payer2 WITH PayersLookup.payer2
            REPLACE Checks.payer3 WITH PayersLookup.payer3
            REPLACE Checks.payer4 WITH PayersLookup.payer4
            REPLACE Checks.payer5 WITH PayersLookup.payer5
            REPLACE Checks.telephone WITH PayersLookup.telephone
            REPLACE Checks.bank1 WITH PayersLookup.bank1
            REPLACE Checks.bank2 WITH PayersLookup.bank2
            REPLACE Checks.bank3 WITH PayersLookup.bank3
            REPLACE Checks.bank4 WITH PayersLookup.bank4
            REPLACE Checks.bank5 WITH PayersLookup.bank5
            REPLACE Checks.transit WITH PayersLookup.transit
            REPLACE Checks.routing WITH PayersLookup.routing
            REPLACE Checks.account WITH PayersLookup.account
      ELSE
            REPLACE Checks.payer_id WITH ""
            REPLACE Checks.payer_code WITH m.cOldValue
            REPLACE Checks.payer1 WITH ""
            REPLACE Checks.payer2 WITH ""
            REPLACE Checks.payer3 WITH ""
            REPLACE Checks.payer4 WITH ""
            REPLACE Checks.payer5 WITH ""
            REPLACE Checks.telephone WITH ""
            REPLACE Checks.bank1 WITH ""
            REPLACE Checks.bank2 WITH ""
            REPLACE Checks.bank3 WITH ""
            REPLACE Checks.bank4 WITH ""
            REPLACE Checks.bank5 WITH ""
            REPLACE Checks.transit WITH ""
            REPLACE Checks.routing WITH ""
            REPLACE Checks.account WITH ""
      ENDIF
ENDIF
THISFORM.Refresh()
RETURN(.T.)

Checks.payer_code does receive the value from DisplayValue, and saves it.  But, the screen field blanks as soon as you leave it.

Maybe my combo box is not the solution?
0
 

Author Comment

by:fmoore0001
ID: 38378479
Ha!  I found some code to make my own class, but I have never build a VFP object: from a prg file.  Any hints on how to do this, or where I start:

**************************************************
*-- Class:        cbonotinlist 
*-- ParentClass:  combobox
*-- BaseClass:    combobox
*-- Time Stamp:   12/12/99 06:38:09 PM
*-- ALLOWS SELECTION OF AN ITEM NOT IN THE COMBO'S LIST TO BE USED AS ITS CONTROLSOURCE...ONLY WORKS IF THE COMBO'S BOUND COLUMN IS 1
*
DEFINE CLASS cbonotinlist AS cboqfill

  *-- Used to save the control source of the combo before the control is unbound
  ccontrolsource = ""
  Name = "cbonotinlist"

  *-- Called from Valid...it updates the "bound" field
  PROCEDURE updatecontrolsource
  LOCAL lcAlias, lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcAlias = JUSTSTEM( .cControlSource )
      IF UPPER( ALLTRIM( lcAlias ) ) = 'THISFORM'
        lcControlSource = .cControlSource
        STORE .DisplayValue TO &lcControlSource 
      ELSE
        REPLACE ( .cControlSource ) WITH .DisplayValue IN ( lcAlias )
      ENDIF
    ENDIF
  ENDWITH
  ENDPROC

  *-- Updates display value from the field in the underlying table if this is a "bound" control
  PROCEDURE refreshdisplayvalue
  LOCAL lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcControlSource = .cControlSource
      .DisplayValue = &lcControlSource 
    ENDIF
  ENDWITH
  ENDPROC

  PROCEDURE Init
  IF DODEFAULT()
    WITH This
      .cControlSource = .ControlSource
      .ControlSource = '
    ENDWITH
  ENDIF
  ENDPROC

  PROCEDURE Valid
  This.UpdateControlSource()
  ENDPROC

  PROCEDURE Refresh
  This.RefreshDisplayValue()
  ENDPROC

  PROCEDURE GotFocus
  IF LOWER( This.Parent.BaseClass ) = 'column'
    *** This is needed so it will work in a grid
    Combobox::GotFocus()
    This.RefreshDisplayValue()
    NODEFAULT
  ELSE
    DODEFAULT()
  ENDIF
  ENDPROC

ENDDEFINE

Open in new window

0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38378690
On another note you can adjust your code slightly to me more readabe:

REPLACE
   field1 WITH value1,;
   field2 WITH value2,;
   field3 WITH value3
0
 

Author Comment

by:fmoore0001
ID: 38378697
Ah, I disagree on that schema.  I have found that I, at least, have a tendency to screw something up in that long list of replacements, where as the:

REPLACE field1 WITH value1

layout I never do.  And, I can insert new field, change fields, etc. with ease once I have finished coding.   I was trained to trade clarify for speed, and usually it has served me well.  Alot either when I ask an unfamiliar programmer to do some thing in my code, too.

Frank
0
 

Accepted Solution

by:
fmoore0001 earned 0 total points
ID: 38378708
Guys,

Thanks you for your help.  it got me on to the right way to do this.

First, i created a new subclass from the base VCX combo box in the CLASSES tab of the project, and added it to the CLASS I wanted it associated with.  Just click on the class you want to draw from, enter the new Class name, specify what type of class it is (in this case a combo box) then direct the save to the CLASS VCX field you want it saved (defaults to the current VCX file, but I wanted it with others of a type).  In my case I did not use the name cboqfill, preferring to stick with the sole name cbonotinlist for my subclass name.

Then, using the code above I either updated or revised methods (Proceduress) named in the code with the corresponding methods in the new VCX and then added the PROCEDURES / Methods not existing in the VCX file but in the PRG file.  Make sure the names are EXACT.  Don't copy in PROCEDURE <name> and ENDPROC - not necessary.

Finally I added the one Property ccontrolsource with a empty value.  What shocked me was it worked the first time I tried it!  If you hand enter text in the Combo Box, it stays!

One note on the above code: In the INIT PROCEDURE

.ControlSource = '

should be:

.ControlSource = ''

Again, thanks for the help.

Frank
0
 

Author Closing Comment

by:fmoore0001
ID: 38390209
Great lesson in converting PRG class files to VCX files.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question