11/26/2024 1:26:42 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
|
|
|
|
Moving values from TreeView to DataGrid
Posted: 25 Aug 06 11:27 AM
|
fiogf49gjkf0d I have a treeview on one side of my form and a datagrid on the other side. When the user selects an item from the treeview and clicks Add>, that value needs to be added to the datagrid. I have been using the code from the Opportunity Products treeview screen and have added the necessary code for selecting single items. However, rather than having a bunch of sub routines, I just combined it all into one since the requirements are a lot less than that of the Opp Products. I am getting an object required error in my code and I am not sure what I am missing. Here is the code that fires to get the selected record moved over from the treeview to the datagrid. I don't want the record to be added to the database until the user selects OK on this form, but I do need the values to be displayed in the datagrid.
Sub GetSelectedEvent Dim strRelEvIDs, strSQL dim objRS, conn dim i
strRelEvIDs = "('" + treRelEv.Selected.Tag + "') "
if not trim(strRelEvIDs) = Empty then strSQL = "Select E1.EventName, E1.EvxEventID " & _ "From EvxEvent E1 " & _ "Where EvxEventID In " & trim(strRelEvIDs)
Set conn = application.GetNewConnection set objRS = CreateObject("ADODB.Recordset") objRS.CursorLocation = adUseClient objRS.LockType = adLockBatchOptimistic objRS.CursorType = adOpenStatic
conn.Errors.Clear
with objRS .Open strSQL, conn if not (.BOF AND .EOF) then for i = 0 to .RecordCount - 1 With grdRelEv.Recordset .AddNew .Fields("EvxEventID").Value = objRS.Fields("EvxEventID").Value .Fields("EventName").Value = objRS.Fields("EventName").Value .Fields("KeyFieldID").Value = .RecordCount & objRS.Fields("EvxEventID").Value end with .MoveNext next end if .Close end with end if set objRS = nothing End Sub |
|
|
|
Re: Moving values from TreeView to DataGrid
Posted: 26 Aug 06 7:22 AM
|
fiogf49gjkf0d Sarah,
It looks like the problem may be in you nested with statements. There appears to be an ambiguous object reference in this line:
>.Fields("KeyFieldID").Value = .RecordCount & objRS.Fields("EvxEventID").Value
It looks like it should be .Fields("KeyFieldID").Value = objRS.RecordCount & objRS.Fields("EvxEventID").Value
Hope this helps
Tom Kaiser Hilltop Information Systems |
|
|
|
Re: Moving values from TreeView to DataGrid
Posted: 26 Aug 06 9:02 AM
|
fiogf49gjkf0d You cannot nest "With" blocks on different objects.
You're doing this:
With objRS With grdRelEv.Recordset End With End With
You can't do that. How will it know which object to reference? It won't cause an error to do so, but you will get unexpected results. Technically, it is allowable, but you must provide a fully qualified object reference in an inner With block to any member of an object in an outer With block, so what's the point?
The only time I recommend you nest With blocks is when it is on the same object. Something like this is ok:
With grdRelEv With .Recordset End With End With
Anyway, check all the references (as Tom mentioned) and that's probably the right track. |
|
|
|
Re: Moving values from TreeView to DataGrid
Posted: 06 Sep 06 9:04 PM
|
fiogf49gjkf0d Thanks for all of the help! I have this working but now am trying to do some error handling when I am at the end of a recordset. Basically from the treeview the user can double-click the item or click on an Add button to add the value to the datagrid on the right-hand side of the screen. I have also given the user the ability to select an item from the right side and click a Remove button to remove it from being added into the database. This is where the problem lies: When the user has removed all of the values from the right side (perhaps to start over, etc) the last value removed from the grid causes an .EOF or .BOF error message. I think it has to do with the fact that the code is calling the .MoveNext but there is not a "next" to move to. What is the best way to address this issue? Thanks...see code below:
Sub RemoveSelectedEvent Dim strRelEvIDs
strRelEvIDs = trim(grdrelev.GetCurrentField("EvxEventID"))
if not trim(strRelEvIDs) = Empty then With grdRelEv.Recordset .Movefirst While not (.bof or .eof) if .fields("EvxEventid").value = strRelEvIDs then .delete end if .movenext Wend end with set grdRelev.recordset = grdRelEv.Recordset grdRelEv.Refresh end if End Sub
|
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|