How to insert the ID value from a text in a database - sql

I've this form and everything works perfect, when the user complete the form all the parameters go to the database and I can show them back, but I've a little problem with something. I've been inserting one field from codebehind like a constant, one of my fiel expect a int value but in the form you select that value as string. For example you select "Pink" in the form but the data base is expecting a int value. The table from Pink has Pink associated to a idValue, e.g. IDColor = 45 Color=Pink. So, what I really need to do is be able to send the ID associated with Pink to the database and when I call back that row, I need to show PInk instead of 45. I know how to make the connection, but I don't know hoy to make the consult. Thanks for your time for reading this and sorry for the long post.
This is the code for insert in the database after the form is ready
cmd.Parameters.Add(New SqlClient.SqlParameter("#IdColonia", 2))
I need to change that "2" for the ID associated with the parameter in the form.
This is the callback for this particular field
Me.txtDirColonia.Text = Me.gridDatos.Rows(Me.gridDatos.SelectedIndex).Cells(7).Text
I call back the ID of the table but I need the actual Color.

Related

(Access) search text field for strings matching those in another table's field and display these matching records in a subform

Here's my situation,
tbl_products / frm_products
ID__products
products__name (short text)
products__description (short text)
tbl_articles / frm_articles
ID__articles
articles__name (short text)
articles__body (long text)
I have a form bound to tbl_articles containing a subform bound to tbl_products.
What I would like to happen is,
once a user enters text into the articles__body field, (using the After Update module)
it searches this long text field for any words which match a product name
and then (in the subform) displays the matching products.
For example if the articles__body record that the user is currently viewing contains 'product 1', it will display product 1's record in the subform.
Perhaps After Update is not appropriate as it needs to appear to remember these matches. For example, if tbl_articles' record 1 matches/displays product 1 on the subform whereas record 2 matches/displays products 2,3 and 4; I need the user to be able to revisit record 1 and see the product 1 match without having to edit the text (and trigger the After Update).
I have no idea where to start with this. It's not a simple if string contains, Originally I entertained the idea of something like - Like '* [in tbl_products, record 1's products__name] *' repeated for each record (obviously not the correct syntax but simply identifying the process to myself), however this is impractical because the number of strings to match against will grow over time as more products are added.
Any help would be great,
Kind regards
Set Filter and FilterOn properties. Suggest naming subform container control different from the form it holds, like ctrProducts.
Me.ctrProducts.Form.Filter = "InStr('" & Me.articles_body & "', [products_name])>0"
Me.ctrProducts.Form.FilterOn = True

Editing SWT Table cell. Changed value jumps back immediately to old value as soon as I leave cell. Why?

I have a Dialog and there is a Table (Tableviewer) inside it.
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI);
Certain columns of my table are editable. I click on the cell, I edit the value, I leave the cell and the edited value immediately reverts back to the old one.
What should I configure/set in table/tablehelper to make the edited values last longer than the time I spend in the cell?
EDIT!-----------------------------
We have a Helper class that is responsible for creating CellEditingSupport like this:
`
if ("w".equalsIgnoreCase(hd_bean_mode)) {
CellEditingSupport editingSupport = new CellEditingSupport(viewer,pds[i]);
col.setEditingSupport(editingSupport);
}`
This class itself is quite complex and does a lot of magic through reflexion, etc... The funny thing however is that other tables use this very same Helper class, seemingly with the same configuration and they work!
One more thing: I am conviced that the columns in my table get the Editingsupport. I know it because of the debugger and because the cells are editable. The only problem is that those edits do not last long.

Dynamically update row contents via dialog screen

I need some help with the following problem. I currently have one dialog screen with a field in which a user can type a number. This number corresponds with an ID field in a database table I've made (using se/11). I want to display the contents of all fields (so only one row of the table) with the corresponding ID on a second screen. The user should also be able to edit the information in the fields and, after saving, those changes should be visible in the table itself. What it comes down to is that I want to dynamically change the contents of the returned row through the dialog screen. I know I have to use a Table Control, but apart from that I'm at a loss (I'm pretty new to ABAP).
Here's the table
Screen 1 where a user can input a number that corresponds to SEQNR in the table
When pressing F8 on Screen 1, I want to go to a second screen with the information of the person with SEQNR = 1, in other words, only this row should appear:
The user should be able to edit the information in this row. When he clicks "Save", the edited information should be updated in the table itself.
So far, I only made a standard second screen in which I added a Table Control for the above table in Screen Painter. I added this control to my DIALOG_TOP:
PROGRAM TAAK1.
DATA: OK_CODE TYPE sy-ucomm,
ls_table TYPE TABEL1,
SEQNR_TEXTFIELD TYPE i,
TXT_STATUS(25) TYPE c,
it_table LIKE TABEL1 OCCURS 0 WITH HEADER LINE.
TABLES: TABEL1.
CONTROLS: TABLE_CONTROL TYPE TABLEVIEW USING SCREEN 200.
I have no code for screen 2, other than the standard PBO and PAI Modules.
The code for screen 1 looks like this.
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'CHECKID'.
SELECT SINGLE * FROM TABEL1 WHERE SEQNR EQ SEQNR_TEXTFIELD.
IF sy-subrc EQ 0.
TXT_STATUS = 'ID BESTAAT'.
ELSE.
TXT_STATUS = 'ID BESTAAT NIET'.
ENDIF.
IF TXT_STATUS = 'ID BESTAAT'.
SELECT * FROM TABEL1 INTO ls_table WHERE SEQNR EQ SEQNR_TEXTFIELD.
ENDSELECT.
ENDIF.
WHEN 'EXEC'.
CLEAR OK_CODE.
SET SCREEN 200.
LEAVE SCREEN.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
I basically check if the Seqnr exists in the table. If it does, I store the corresponding row in a local structure which I've defined in the DIALOG_TOP.
It's probably easier and less time consuming to use an SM30 view. You can create a custom transaction to maintain the correct authorizations. Additionally you can adjust the screens (see the code of the generated function group) to your liking's.
More info here:
https://help.sap.com/saphelp_nw73ehp1/helpdata/en/cf/21ed2d446011d189700000e8322d00/content.htm
https://archive.sap.com/discussions/thread/851998
http://saptechnical.com/Tutorials/ABAP/TableMaintenance/demo.htm

Get value in textbox depending on combobox

I have searched high and low for an answer to this. Lots of places come close to what I need but try as I might I can't find exactly what I need. So, here goes. I have a combo box on a user form that reads values from a table. when a user makes a selection, depending on how far down the table the selection falls, I would like a textbox to display one of two strings. I'm currently using a toggle button which seems a bit 'clunky. I'm fairly new to vba so be gentle with me.
Me.textbox.Value = Me.combobox.Value
will give you the value of the bounded column of the selected row, usually the first one (e.g. if your combobox shows data like ID;LastName;PreName, it shows the ID)
If you want to show other colums than the bounded one, use
Me.textbox.Value = Me.combobox.Column(n)
(n stands for the column, beginning at 0 for the first, 1 for the second, ...)
So if you want to show the LastName of the previous example, go with
Me.textbox.Value = Me.combobox.Column(1)
If you just want to show the string when it doesn't fit in the combobox column, I'd make it like
If Len(Nz(Me.combobox.Column(1))) > n Then
Me.textbox.Value = Me.combobox.Column(1)
Else
Me.textbox.Value = Null
End If
There might be another solution, but this would be an easy one

How to set value in the textblock based on other textboxes and query in Access?

Right now I have such form:
The aim, that I'm trying to reach, is to open another form based on block_id value by pressing button. And it works. But block_id value in textblock should be based on three other values in the form: N_table, target_table and source_table. In the attached picture can be seen block_id's textblock form options. Source values for that textblock is query with name s2, and I tried to limit block_id value by setting filter here this way:
([s2].[N_table]=[Form1].[Список0]) AND
([s2].[target_table]=[Form1].[Список2]) AND
([s2].[source_table]=[Form1].[Список4])
There s2 is the query name, Form1 is the name of current form, Список0 and so on is the just list of values for first 3 textboxes. However that doesn't work at all. So block_id is independent. That is wrong here and how it can be fixed?
PS I'm really sorry for not english language in the attached picture, I can't change the language. And I tried to deal with the problem by using Event Processing macros but failed.
I can't read your language, but it looks if the FilterOnLoad property is set to No. Change it to yes, then it should work.