×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Why is new record not showing in dropdown list?
2

Why is new record not showing in dropdown list?

Why is new record not showing in dropdown list?

(OP)
Hi experts… i have an application than can add and delete record, and it can be accessed thru network… my question is, why is record added in the client computer not showing in other computers in the network? Its on shown where the record is added… in other computers, i need to close the application first before the new record is shown? Thanks and god bless…

RE: Why is new record not showing in dropdown list?

You probably need to requery the source on the the control you are using that should have the
record showing, beit a grid or combo or whatever

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Why is new record not showing in dropdown list?

Mandy, you mention a drop-down list. How are you populating that list? If the list already exists at the point when the table is updated, you will need to re-populate it, probalby using list's Requery method.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Why is new record not showing in dropdown list?

Another possibility ...

On the machine that's doing the inserts and deletes, are you using buffering? If so, the changes will need to be committed (usually via TABLEUPDATE()) in order for them to be seen by other machines on the network.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Why is new record not showing in dropdown list?

Both Mike and Griff have a point about two different reasons. To find out which one applies ideally you should generate exactly that situation and then use a third computer and browse the DBF on it. That would show you whether the new or deleted record arrived in the DBF file already or not, it's the simplest way to check this. And you may do that by using the application on two clients, showing the form with the dropdown list in one of them, adding a record in the other, and on your development computer open up the dbf and BROWSE it.

If your computer doesn't see the data change, the change is still not saved and the simplest reason for that is what Mike said, the client that added the new record only has it buffered for itself and nobody else can see it until you actually save the buffer.

If your computer does see changes, then what Griff explains plays a role. Even though the data is already available to you and also all other clients in that case, the control may still show the old state. Notice that in a combobox (which I assume you mean) even when using the rowsourcetypes "alias" or "fields" which get data from a workarea, the combobox will fill its internal listitems array. This means, even if you don't manually copy all data from a dbf with Additem(), the combobox actually shows its listitems, not the DBF directly. If there is a new record, this doesn't necessarily become a listitem.

Those are independent reasons and they can also both be true at the same time. You unfortunately can't solve it by adding in TABLEUPDATE() as a prophylactic action. If buffering isn't even used only Griffs idea of the problem explains it. I tested this and prepared such a situation. Then even combobox.requery() didn't reread the alias and refreshed the listitems. I used a dbf and added a new record unbuffered in a separate VFP IDE, so I ran VFP twice. The only thing that made the new record show up was using GO TOP, LOCATE or SKIP or showing the datasession window within the session showing the combobox. That's actually a strange problem.

So, if that is the case you actually found a VFP bug. Or I am failing in some other global setting like REPROCESS or REFRESH. Anyway, it can happen even with unbuffered workareas.

Chriss

RE: Why is new record not showing in dropdown list?

Mandy,

If you and I actually found a bug, a workaround solution for that I found is doing this in the combobox.WHEN() method:

CODE

If InList(this.RowSourcetype,2,6)
  if used(this.RowSource)
     =Reccount(this.RowSource)
  else
     =Reccount(juststem(this.RowSource))
  endif
EndIf 
Just accessing the reccount() of the alias/workarea that is the rowsource of the combobox makes it requery the data. That also works in case the change is a delete and reccount() doesn't even change (because deleted records are still counting for the dbf record count in any mode).

It's not a solution to buffering, though. Indeed not saving buffered changes you can't do anything on the client that doesn't ssee the new or modified data, you have to wait until the other user saves changes for everyone else to see them.

Chriss

RE: Why is new record not showing in dropdown list?

Quote (Mandy)

i need to close the application first before the new record is shown
That automatically saves buffered changes on the computer of the user making the changes and also rereads the data for the combobox on the other computer. So it does not decide whether your problem is buffering or control requery.

I don't assume my code for the combobox.when() will solve your problem, as I think it's more likely buffering is causing the data not to be seen on any other computer, and that's not a bug, that's just what buffering is: Keeping changes to yourself until you finally commit the buffer.

Chriss

RE: Why is new record not showing in dropdown list?

(OP)
Hi Chriss and Mike... I will be trying what you have suggested Chris... I pray that it should work... Thank you so much to both of you...

RE: Why is new record not showing in dropdown list?

Hi Mandy,

Quote (Mandy)


I pray that it should work

Well, that's probably not the best way to approach the problem. Why don't you just post

  • the code of your save/update procedure(s) for your table(s)
  • how you populate the combobox
  • and how you update it


  • Below a sketch how you could do this (Table buffering is set to 5 to show the effect of TABLEUPDATE() in the AFTERROWCOLCHANGE() procedure of the grid)

    How to test:

    You run the code, open the combobox and click a name. You add a record and reopen the combobox - the new record was added. You then change one name in the grid and open the combobox again without leaving the grid's cell - the changes are NOT visible. Then you move the pointer in the grid and - voilà - the changes are visible in the combobox.

    CODE -->

    PUBLIC goForm
    
    goForm = NEWOBJECT("form1")
    goForm.Show
    Read Events
    
    Close all
    Clear All
    
    RETURN
    
    
    **************************************************
    DEFINE CLASS form1 AS form
    	DIMENSION gaNames[1]
    	
    	DataSession = 2
    	AutoCenter = .T.
    	Caption = "Grid with combobox"
    	MinHeight = This.Height
    	MinWidth = This.Width
    	MaxWidth = This.Width
    	
    	ADD OBJECT lblRNumbers as Label WITH ;
    		Left = 270, Top = 9, Caption = ""
     
    	ADD OBJECT grid1 AS grid WITH ;
    		ColumnCount = -1, ;
    		Left = 12, ;
    		Top = 36, ;
    		Width = ThisForm.Width - 24, ;
    		Height = ThisForm.Height - 72, ;
    		RecordSource = "curTemp", ;
    		Anchor = 15
     
    		PROCEDURE grid1.Init
    			WITH This.Column1
    				.Width = 90
    				.Header1.Caption = "Name"
    			ENDWITH
    		 ENDPROC 
    
    *!*	code to update the table		 
    
    		 PROCEDURE Grid1.AfterRowColChange()
    		 	LPARAMETERS lnRowColIndex
    		 	
    		 	LOCAL liNextRecord
    	
    			liNextRecord = GETNEXTMODIFIED(0, "CURTEMP")
    	
    			DO WHILE liNextRecord > 0
    				GOTO liNextRecord
    				
    				= TABLEUPDATE(1, .T., "curTemp")
    
    				liNextRecord = GETNEXTMODIFIED(liNextRecord, "CURTEMP")
    			ENDDO 
    		 ENDPROC 
    
    *!*	end of code to update the table		 
     
     	ADD OBJECT cboNames AS ComboBox WITH ;
    		Left = 12, ;
    		Top = 6, ;
    		Height = 24, ;
    		Width = 120, ;
    		Style = 2, ;
    		RowSourceType = 5, ;
    		RowSource = "ThisForm.gaNames"
    		
    
    *!*	code to populate/refresh the combobox		 
    
    		PROCEDURE cboNames.GotFocus()
    
    			SELECT * FROM curTemp INTO ARRAY ThisForm.gaNames
    
    			WITH This	
    				.Requery()
    				.Refresh()
    			ENDWITH 
    		
    		ENDPROC 
    
    *!*	end of code to populate/refresh the combobox		 
    		
    		PROCEDURE cboNames.Click()
    			LOCATE FOR cName = ALLTRIM(This.List[This.Listindex, 1])
    			
    			ThisForm.Refresh()
    		
    		ENDPROC 
    
    	ADD OBJECT cmdAddName as CommandButton WITH ;
    		Left = 144, Top = 6, Height = 24, Caption = "Add name"
    
    *!*	code to add a record to the table and save it
    		
    		PROCEDURE cmdAddName.Click()
    			INSERT INTO curTemp VALUES ("Edward")
    
    			= TABLEUPDATE(1, .T., "curTemp")
    			
    			WITH ThisForm
    				.lblRNumbers.Caption = IIF(ALIAS() = "CURTEMP", TRANSFORM(RECCOUNT("curTemp")), "0")
    				.Refresh()
    			ENDWITH 
    		ENDPROC 
    
    *!*	end of code to add a record to the table and save it
    
    PROCEDURE Destroy
    	ThisForm.grid1.AfterRowColChange()		
    	
    	Thisform.Release()
    	CLOSE ALL
    	Clear Events
    ENDPROC
    
    PROCEDURE Load
    	
    	SET Multilocks ON 
    
    	CREATE CURSOR curTemp (cName C(20))
    	
    	INSERT INTO curTemp VALUES ("Allan")
    	INSERT INTO curTemp VALUES ("Jane")
    	INSERT INTO curTemp VALUES ("Margie")
    	INSERT INTO curTemp VALUES ("Kim")
    	
    	LOCATE 
    	
    	= CURSORSETPROP("Buffering", 5, "CURTEMP")
    	
    ENDPROC
    
    ENDDEFINE
    ********************************************* 

    hth

    MarK

    RE: Why is new record not showing in dropdown list?

    (OP)
    Thanks Mj... I will try to study the code... and probably make necessary changes to my application.... Thanks and God bless...

    RE: Why is new record not showing in dropdown list?

    (OP)
    Hi mjcmkrsr... What you have suggested worked!!!! I can now see the record added to a client....and anywhere in the client computers.... Thank you so much... God bless....

    RE: Why is new record not showing in dropdown list?

    2
    Hi Mandy,

    Glad to read that my hints helped you solve the problem.

    Below a slightly pimped-up and smoothed version of the same code snippet. It also allows you to delete records - just click the little white rectangle on the left side of the record in the grid and then click another record - the table awa the combobox will be updated.

    CODE -->

    PUBLIC goForm
    
    goForm = NEWOBJECT("form1")
    goForm.Show
    
    Read Events
    
    Close all
    Clear All
    
    RETURN
    
    
    **************************************************
    DEFINE CLASS form1 AS form
    	DIMENSION gaNames[1]
    	
    	DataSession = 2
    	AutoCenter = .T.
    	Caption = "Grid with combobox"
    	MinHeight = This.Height
    	MinWidth = This.Width
    	MaxWidth = This.Width
    	
    	ADD OBJECT grid1 AS grid WITH ;
    		ColumnCount = -1, ;
    		Left = 12, ;
    		Top = 36, ;
    		Width = ThisForm.Width - 24, ;
    		Height = ThisForm.Height - 48, ;
    		RecordSource = "curTemp", ;
    		Anchor = 15
     
    		PROCEDURE grid1.Init
    			WITH This.Column1
    				.Width = 90
    				.Header1.Caption = "Name"
    			ENDWITH
    		 ENDPROC 
    
    *!*	code to update the table		 
    
    		 PROCEDURE Grid1.AfterRowColChange()
    		 	LPARAMETERS lnRowColIndex
    		 	
    		 	LOCAL liNextRecord
    	
    			liNextRecord = GETNEXTMODIFIED(0, "CURTEMP")
    	
    			DO WHILE liNextRecord > 0
    				GOTO liNextRecord
    				
    				= TABLEUPDATE(0, .T., "curTemp")
    
    				liNextRecord = GETNEXTMODIFIED(liNextRecord, "CURTEMP")
    			ENDDO 
    			
    			ThisForm.Refresh() 
    			
    		 ENDPROC 
    
    *!*	end of code to update the table		 
     
     	ADD OBJECT cboNames AS ComboBox WITH ;
    		Left = 12, ;
    		Top = 6, ;
    		Height = 24, ;
    		Width = 120, ;
    		Style = 2, ;
    		RowSourceType = 5, ;
    		RowSource = "ThisForm.gaNames"
    		
    *!*	code to populate/refresh the combobox		 
    
    		PROCEDURE cboNames.GotFocus()
    
    			SELECT * FROM curTemp WHERE NOT DELETED() ORDER BY 1 INTO ARRAY ThisForm.gaNames
    
    			WITH This	
    				.Requery()
    			ENDWITH 
    		
    		ENDPROC 
    
    *!*	end of code to populate/refresh the combobox		 
    		
    		PROCEDURE cboNames.Click()
    			LOCATE FOR cName = ALLTRIM(This.List[This.Listindex, 1])
    			
    			ThisForm.Refresh()
    		
    		ENDPROC 
    
    	ADD OBJECT cmdAddName as CommandButton WITH ;
    		Left = 144, Top = 6, Height = 24, Caption = "Add name"
    
    *!*	code to add a record to the table and save it
    		
    		PROCEDURE cmdAddName.Click()
    			INSERT INTO curTemp VALUES ("Edward")
    
    			= TABLEUPDATE(1, .T., "curTemp")
    			
    			WITH ThisForm
    				.Refresh()
    			ENDWITH 
    		ENDPROC 
    
    *!*	end of code to add a record to the table and save it
    
    PROCEDURE Destroy
    	ThisForm.grid1.AfterRowColChange()		
    	
    	Thisform.Release()
    	CLOSE ALL
    	Clear Events
    
    ENDPROC
    
    PROCEDURE Load
    	
    	SET Multilocks ON 
    	SET DELETED ON 
    
    	CREATE CURSOR curTemp (cName C(20))
    	
    	INSERT INTO curTemp VALUES ("Allan")
    	INSERT INTO curTemp VALUES ("Jane")
    	INSERT INTO curTemp VALUES ("Margie")
    	INSERT INTO curTemp VALUES ("Kim")
    	
    	LOCATE 
    	
    	= CURSORSETPROP("Buffering", 5, "CURTEMP")
    	
    ENDPROC
    
    ENDDEFINE
    ********************************************* 

    MarK

    RE: Why is new record not showing in dropdown list?

    (OP)
    Ok mjcmkrsr ill try to read it well and study... Thank you so much for always helping... God bless...

    Red Flag This Post

    Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

    Red Flag Submitted

    Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
    The Tek-Tips staff will check this out and take appropriate action.

    Reply To This Thread

    Posting in the Tek-Tips forums is a member-only feature.

    Click Here to join Tek-Tips and talk with other members! Already a Member? Login


    Close Box

    Join Tek-Tips® Today!

    Join your peers on the Internet's largest technical computer professional community.
    It's easy to join and it's free.

    Here's Why Members Love Tek-Tips Forums:

    Register now while it's still free!

    Already a member? Close this window and log in.

    Join Us             Close