I was able to display data from my MySQL table using this code:
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
tb_lname.Text = datardr("SURNAME")
tb_fname.Text = datardr("GIVEN")
tb_mname.Text = datardr("MID")
tb_mi.Text = datardr("MIDDLE")
tb_app.Text = datardr("APPELLATION")
tb_prefix.Text = datardr("PREFIX")
tb_sex.Text = datardr("SEX")
tb_status.Text = datardr("STATUS")
End If
However, I noticed that it's not displaying all data coming from these fields. I can only view the SURNAME, GIVEN, MID and MIDDLE but the others are not displayed.. I have double checked my database fields and I'm sure that they're the same and without special characters or whitespaces.
Please help. Thanks!
Here is the exact code that I have => VB2010 and MySQL Code
Alright, here's another answer for you.
I think it's because of your SQL statement in line 21.
I assume you are selecting ONE record (am I right?), so that you can insert the resultant fields into the text boxes. And, you order the result with SURNAME.
Did you double check whether there are already data inside the masterlist table? Especially check, if you already entered the data in every field in every row.
In line 30, you called datardr.Read() method, so the DataReader object datardr will read the first record line it encountered in the result of the sql statement.I think only the four fields of the first record, SURNAME, GIVEN, MID and MIDDLE has data values, and any other fields contain null values. So, you only got these FOUR values appeared inside the text boxes, and any other fields appeared to be blank.
I THINK IT MIGHT BE THE MAIN PROBLEM. Just check whether the data you wanted to be appeared already existed in the database table. OK!
And another suggestion. Don't you think you might need WHERE clause in your SQL statement? Well, you want to display only one record, don't you?
WISH YOU BEST LUCK!!! :-)
I think you better check the sql statement that passed into the command object, cmd.
Maybe you didn't select the entire record with select *.
And, one more recommendation.
If datardr is the DataReader, I highly recommend you NOT to use it. It cause much problems than it serves.
The more flexible approach is to use just the DataTable.
The command object has ExecuteNonQuery method that returns the DataTable object.
It is more flexible and much more easier to use than DataReader. Trust Me...! ;-)
Related
I'd like to know if there is a way to make a field in a query dependent on a value from a text field on a form. Namely, I'd like to take a field from a table and multiply it by a value from a field on a form.
I tried Input(mg): [Percent]*[forms]![frm_Formulation]![Text4] but the field is blank when I run the query.
When I remove [forms]![frm_Formulation]![Text4] my percent field shows up as it should.
Cross post http://www.accessforums.net/showthread.php?t=68017
Suggested Edit: Here is my SQL: SELECT Tbl_Formulas.Item, Tbl_Formulas.RawMaterial, [Percent]*1257 AS [Input(mg)], Tbl_Formulas.[Quantity(kg)], Qry_Percentages.Percent
FROM Qry_Percentages INNER JOIN Tbl_Formulas ON (Qry_Percentages.Item = Tbl_Formulas.Item) AND (Qry_Percentages.[Quantity(kg)] = Tbl_Formulas.[Quantity(kg)])
WHERE (((Tbl_Formulas.Item)="a475ad"));
I tried to recreate this instance in a new database and could not. The function works. It just doesn't work in this db...
Thank you all for the responses. I figured out the problem. One of the relationships in my table were screwing with the query. Resetting the relationships solved the issue and now the function works properly. Thanks again, especially June7. You've helped me out many times now.
I am attempting to maintain and fix a horribly out-of-date CRM designed by an ex-employee ~4-5 years ago in Access 2007. I have brought it into Access 2013 and fixed a ton of stuff up, but I am still running into many problems.
I spent a good 4 hours today attempting to figure out why certain values didn't line up. These values were being pulled from a SELECT statement on a Combo Box over a stored Query which simply returns a table with a few extra rows. Great.
However this value (a number) doesn't appear to correlate with what we expect. I enter in one value, save the ticket, and a completely different value gets stored into the table. Opening up the ticket, I see the value that I expect. Digging deeper, I found the following difference:
Set value_1 = Me.RegistrationID // What's being stored in the table
Set value_2 = Me.RegistrationID.Column(0) // What we expect
Surprise surprise! This is a Combo Box and some value is being stored in the table. The Control Source is "RegistrationID" and the Row Source is the query in question.
However I do not know what it is! This specific value correlating to the Combo Box appears to pull the correct data when we later open the tickets. However I have a strong feeling that this could be why many tickets from before one of the rows was deleted all appear to have invalid RegistrationID's.
How badly can this break?
How easily can we correct tens of thousands of tickets?
How can I fix this to store the correct value?
This is what I expect is happening.
Your combo box row source is based on a Select query which returns and displays multiple rows. For example:
Select RegistrationID, CustomerID, CustomerName From MyTable;
The Control Source for the combo box is bound to RegistrationID which is part of the Forms Record Source.
The issue is the bound column. If we set the bound column in our example to 1, then we get the behavior your are describing with:
Set value_1 = Me.RegistrationID - Set's value to CustomerID (may appear correct)
Set value_2 = Me.RegistrationID.Column(0) - position 0 from our query (RegistrationID)
Further building on our query example, you can say:
Me.TextBox1 = Me.RegistrationID.Column(0) - RegistrationID
Me.TextBox2 = Me.RegistrationID.Column(1) - CustomerID
Me.TextBox3 = Me.RegistrationID.Column(2) - CustomerName
The RegistrationID is what normally should be stored in the table.
As long as your form shows any values that directly relate to this RegistrationID you're fine.
I would start by checking to see under the format setting to see if column widths are set properly and I would also check under the data section to see if the bound column is correct. I might also throw in an after update macro/vba sub routine that saves the record. Hope this helps.
I have a table with rows and where one field is a bit-value with 7 digits.
Suppose I have a procedure where I want to select all rows where this bit field equals '0101010', this is easily done by select * where .... and so on.
But: how do I do if I want to allow one/multiple digits of the digits to be either 1 Or 0, i.e I want to get all rows where the bitfield has an entry on the form 1001*1* where the * can be either 1 or 0. So, in this case I would like all entries where the bit field is 1001010, 1001011, 1001110 or 1001111.
select * from TABLE where bit_field in (1001010, 1001011, 1001110, 1001111) would probably work in this example, but if I want to use only the string '1001*1*' as input to the procedure, what then?
.
Any help is very appreciated.
Thanks,
Niklas
Edit: I've tried this: select * from table where field like bit'\\\0'; for getting all entries of the form **0, but that didn't work...
Edit2: It turned out it vas a bit-field, not binary... problem still remain though.
Not a direct answer to your question, per se', but an alternative approach. You mentioned that you didn't want to convert to individual columns because of legacy code. If you do want individual columns and the only thing holding you back is the legacy code, consider the following.
You could add columns for the options and use insert/update triggers to populate them OR you could create a view that splits the bits into separate columns. For new development, you can code to the new columns. Over time, as you modify legacy code you can change it to the new approach. When all the "read" legacy code has been changed, the last step is to change the "write" code to use the new columns rather than the bit column and remove the triggers.
I have a SQL Fiddle demonstrating this here. Note that I only included an insert trigger for brevity.
I have the following query in access used in a report for data selection. It works except that it truncates the What_happened field.
The sql database has the what_happened field as a nvarchar(max) - access 2010 see's it as a memo field.
I need to be able to see the full contents of the what_happened field on the report form
Thank you,
Steve
SELECT DISTINCT dbo_all_clients_view.people_id,
dbo_all_clients_view.full_name,
dbo_event_log_shack.actual_date,
dbo_all_clients_view.is_active_client,
[dbo_all_clients_view query].policy_num,
dbo_event_log_shack.event_log_id,
dbo_all_clients_view.dob,
dbo_event_log_shack.eventtime1,
dbo_event_log_shack.is_deleted,
dbo_event_log_shack.staff_name,
dbo_event_log_shack.staff_supervisor,
cir_descrip_staff_resp.what_happened
FROM cir_descrip_staff_resp
RIGHT JOIN ((dbo_all_clients_view
LEFT JOIN dbo_event_log_shack
ON dbo_all_clients_view.people_id =
dbo_event_log_shack.people_id)
LEFT JOIN [dbo_all_clients_view query]
ON dbo_all_clients_view.id_no =
[dbo_all_clients_view query].dbo_all_clients_view_id_no)
ON cir_descrip_staff_resp.[event id] = dbo_event_log_shack.event_log_id
WHERE (( ( dbo_event_log_shack.is_deleted ) = false ))
ORDER BY dbo_all_clients_view.full_name,
dbo_event_log_shack.actual_date DESC;
A great many things cause memo fields to be truncated. In a report, you can DlookUp the memo or use another query to get the full text.
There is a pretty good list of possible reasons here: http://allenbrowne.com/ser-63.html
I was looking for this answer as I knew I had found out how to fix this from a post a few years ago. I subsequently remembered how and it is the most excruciating bad bit of work I have known. As it seems to have been lost from the current knowledge I thought I would put it back out there.
When you are in the export window, click advanced. It shows a grid of field information. If you put your mouse over the 'Field name' heading and then move it right the cursor turns to a line with 2 arrows, move farther to the right and it turns to 2 lines with a space and 2 arrows. Click and drag right and you by magic get the skip field, go back to field name heading , do the same again and you magic the indexed, repeat and magic the width then the start and next time the data type. Ah the data type says it will be exported as a short text field, change it to long text and that is what it exports.
If you are using import/export saved specs to put in your vba, you can similarly expose the data type it will be exported as.
It works with older versions and it works with SQL server linked odbc tables.
I've also just realised that those one field queries probably aren't needed either if you select the skip option for the ones you don't want.
Hope this helps someeone :)
I have an Access query that has a some what complex field on it. Basically, I'm searching for a certain value, based on other derived criteria. The function either works, or it gives a #Func! error. There are a few reasons why I may get an error. That is fine, because in those cases I want to return Null.
How can I test and handle a #Func! error from within a query? Also, I tried to wrap the expression in an IsError() method, and handle that case. That still didn't work.
If, for example, you are using Instr with a field that may or may not be null, and that is causing the problem, you can either select only those fields that are not null, or concatenate an empty string with the field.
SELECT Mid(AField & "",Instr(Afield & "","x")) FROM Table
I don't think this is the optimal solution, however, my hope is that the "higher powers that be" within Microsoft that manage Microsoft Access understand exception handling and would provide some way of testing and handling/ignoring errors, where appropriate.
Regardless, in my case I found a hack to the problem. I save the query just as it was and I exported it to a table. Since this was a one-off exercise, I was able to extract the necessary data and then filter out all Null values from the newly created table.
It worked, but it feels like a really poor hack.
OMGGGGG I know im 6 years late but This is the first time I'm posting on a blog because I actually solved the issue!! You have no idea how excited I am. OK so it turns out this is exactly what I was trying to do: Mid(AField,Instr(Afield,"x")). In my case I knew the InStr function did not always find x in Afield, and in those cases ideally I wanted a Null. But What it actually returns is a 0. In access, functions like Right, Left and Mid CANNOT "START" AT 0, They must start at 1 (or -1 I suppose). Which is what is causing the #Func! error!
One solution....if your Instr fuction=0 do one thing other wise do something else.
If I think of another solution, I let you know.