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 :)
Related
I have a lot of checkboxes (with yes/no fields in the underlying tables) and lately Access has been crashing a lot. After some research it seems null values in the checkboxes could be to blame, so I set out to follow Allen Browne's instructions (http://allenbrowne.com/NoYesNo.html) for replacing them with number fields. Everything was going great until I got to the step where I set the display control to 106 (checkbox). This is not an option in the table and I don't understand why. I set my table up like he stated but I only have the option for a textbox, listbox, or combobox.
I also tried just typing 106 into the Display Control field, but it gives me an error that it isn't an item on the list. In his article, he mentions to fix the error above to use SetPropertyDAO(), but I have no idea what that means, how to do it, or where to do it. Do I built it in code somewhere? The link he has brings you to a script where he uses that to fix his printers or something.
Close your table.
Open Immediate Window with Ctrl+G
Paste the code:
CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl") = CInt(acCheckBox)
Replace table and field name to your names.
Run the code by putting the cursor at the end of the line and hit Return.
If you get an error, open the table in design view, and set the display control to something (it doesn't matter what), save and close, repeat.
I have a field with a customer ID that should be in the format of C0000000001, where it has a letter at the start and up to 10 numbers after the letter with leading zeros between the letter and the number. I want the users to be able to put in C1 and have the table save C0000000001 or C1234 and have the table save C0000001234.
I want the restriction to be on the hard data in the table. The table should contain the full customer ID but I only want the users to have to enter the C and the number of the customer when entering/searching for customers. I am using Access 2010.
I believe that the first character will always be a C, but either way, it would only be one alpha character if it wasn't.
I understand what you are saying, but the majority of the data (thousands of records) are going to be from another system that stores them that way. Doing it this way limits my margin of error. Otherwise, exports from the other system will need to be manually changed prior to being imported into the database and vice versa.
Searching would only be on existing records that will be saved in the C0000001234 format, but I would like user to be able to omit the leading zeros when entering the search criteria.
This question, combined with your previous question here, suggest to me that you are trying very hard to have the data structure in your Access database exactly match the legacy system from which you receive bulk updates. That may not be necessary, or even desirable.
For example, instead of maintaining the CustomerId as Text(11) (as in the old system) you could store it in your Access database as
CustomerIdPrefix: Text(1), and
CustomerIdNumber: Long Integer or perhaps Decimal if the numeric part really can exceed 2,147,483,647
Your Customers table in Access could also include a calculated field named CustomerId as
[CustomerIdPrefix] & Right("0000000000" & [CustomerIdNumber], 10)
to give you a single 'C0000012345' value for display purposes.
For searching, your form could have a Text Box for the Prefix (default value: 'C') and another text box for the numeric part. The search could then use a condition like
[CustomerIdPrefix] = txtPrefix.Value AND [CustomerIdNumber] = txtNumber.Value
or, if the user wanted to create a Filter on the Form (or Datasheet View) it would probably be sufficient to just filter on the number part.
If you ever needed to feed information back to the legacy system you could just export a query that includes the [CustomerId] calculated field (and omits [CustomerIdPrefix] and [CustomerIdNumber]) and you'd be fine.
My suggestion would be to use forms with associated queries using the FORMAT function.
You do need to clarify where you want this implemented, but I'm going to assume you have a table set up and that you would like to be able to enter/search data from a form.
I'll create one form for input frmAdd. For the input form, I created a query that would run when a button on the form was pressed. Add two text boxes newID and newOther to the forms which are unbounded but which the user can use to enter data. The query will then pull that data and append it to your table in an altered format. Here's the SQL for that query:
INSERT INTO Customers ( [Customer ID], [Other Field] )
SELECT Left([Forms]![frmAdd]![newID].[value],1)
& Format(Right([Forms]![frmAdd]![newID].[value],Len([Forms]![frmAdd]![newID].[value])-1),"0000000000")
AS Expr1, Forms![frmAdd]!newOther AS Expr2
FROM Customers;
I'm not sure exactly what search functionality you're looking for, but this query would pull up the record data matching that of a frmSearch with a textbox search which would have the format C### or whatever entered in:
SELECT Left([Customers].[Customer ID],1) & Replace(LTrim(Replace(Right([Customers].[Customer ID],9),'0',' ')),' ','0')
AS Expr1, Customers.[Other Field]
FROM Customers
WHERE (((Customers.[Customer ID])=Left([Forms]![frmSearch]![search].[value],1)
& Format(Right([Forms]![frmSearch]![search].[value],Len([Forms]![frmSearch]![search].[value])-1),"0000000000")));
Applying the input mask is just a way to ensure that your data is correct. If you feel the need to use one, go to the table in Design View and click on the Data Type box for the customer ID field. Find Input Mask under Field Properties -> General and click it. Then hit go to the toolbar -> Design tab -> Builder. This will walk you through it.
Input mask is not the answer for this. Input mask forces the user to input the data in a certain manner. What you need is some VBA code to run in the AfterUpdate event on a form. There's no way within the table to force the data into this pattern allowing the input method that you've requested.
There may be a more efficient way to do this, but this does the job.
http://pineboxsolutions.com/access/customeriddemo.accdb
I have 2 bugs beginning to show up in my app, both in subforms. New text boxes, labels and check boxes will only display in design view.
Bigger problem: I can add a check box by dragging it from the field list but get the error 'Control can't be edited; it's bound to an unknown field [FieldName]' when I attempt to click it in form view.
I can edit the value directly in the table and I can edit the value in the form's underlying query as well.
I've tried decompiling/recompiling and importing all my objects into a new database. I tried using a different machine to see if there was something wrong on mine. nada
This is an existing application with hundreds of man hours into it. I can't just start from scratch.
I was getting this - It took me a while to realize because the error statement only persisted while data list item was click-depressed. It turns out in my case that somehow a number of spaces existed in the Control Source property. I found this when I entered the table name in the field and the error statement switched from Control can't be edited; it's bound to an unknown field '(bunch of spaces) ' to Control can't be edited; it's bound to an unknown field [tableName]. After deleting the [tablename] and ensuring no spaces in Control Source, the combobox toggled to 'unbound' and there was peace in the valley.
I had a similar problem. After many hours of work I discovered that all of a sudden I had to add the table name to the Control Source property.
Go to the properties for the control and add the table name i.e. tbl_MyTable.MyField.
I have no idea why Access sees an ambiguity problem all of a sudden for just that one field but that was obviously the case.
I had this problem and tried adding the table name to no avail. On the load event of the form, I changed the recordset (same table but filtered using what is passed by me.openargs instead of on the docmd.openform command due to needing the id passed for other things to work) in VBA. I thought that once you set the form to the recordset, you were done and could close the recordset. Not so, leave the recordset open until you actually leave the form or this error will occur.
Change the control source from "=[Some_Value_in_Table]" to [Some_Value_in_Table]. To be more precise remove the equal to sign.
I tried all these things - to no avail. I had a few fields bound and only one of them was causing grief - the others were fine. I swapped the Control Source around between controls to isolate the issue - it was definitely only related to the field somehow - after refreshing external links, removing and re-adding the offending field from the Access query opening and closing the offending form - everything somehow fell into place - I can't say exactly what fixed the problem - but my life can now return to normal! In a nutshell - these are the steps I followed:
* refresh links to external table
* remove and re-add fields in query
* confirm the the field is editable at the query level
* copy and paste the table.fieldName from the query's sql statement
* save - close query
* paste into the Control Source
* save and close form!
Good luck!
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...! ;-)
I have a report whose record source is a query, say qryRecords. In the report header I want to add a lengthy notes field (longer than 255 characters). I have set up a table to hold these notes (with a field type "memo"), and because that table is separate from the record source for the report, I was going to put the Notes field in the report using VBA code.
In the open event of the report, I have added this code:
Dim rst as Recordset
Dim sql_qry as String
sql_qry = "SELECT notes FROM tblNotes WHERE id = 1;"
Set rst = CurrentDb.OpenRecordset(sql_qry)
rst.MoveFirst
Me.txtNote = rst![notes] 'I get the run-time error on this line
Unfortunately I get a run-time error where noted ("You can't assign a value to this object"). I found a person with a similar issue on a form, and the suggestion was to move the code from the open event to the OnCurrent event, but that event doesn't exist for a report. Any suggestions? Thanks.
--- Original Question ---
I have a form with an unbound text box (txtNotes), and when the user opens the form, the text box is populated with text that is longer than 255 characters (it concatenates various fields from the database). This works with no problem.
There's a button on the form that opens a report, and in the report, I set the Control Source for a text box to Forms![frmMain]![frmSub]![txtNotes], which is the text box mentioned above. That works too, but for some reason the text on the report is truncated at 255 characters. The form's text box is unbound, so there's no underlying table to limit the length. Does anybody know why this would happen or if there's a workaround?
Most likely when the data from the field is being cast as a Text type rather than as a Memo. Really there's no way to explicitly cast a Text as a Memo (you can go the other way around though with CStr). I had problems with truncation on the form as well when experimenting with this scenario.
I'd suggest you are probably generating this field on the form in the wrong way. Dollars to doughnuts you could generate it in a query (used in the form's Control Source), rather than concatenating it together and placing into an unbound field. Likewise, you could then use that same query as the control source for the report that you are opening.
If all of that is truly impossible, I'd point you at dumping the values from the form into a table specifically for the report and then using the table as a control source for the report.
---- Edit ----
I still contend that you can add it to your Report's data source. In my example below, I've tacked on tblNotes to a select on the Bar table.
SELECT bar.f0, bar.f1, bar.f2, bar.f3, tblNotes.notes
FROM bar, tblNotes
WHERE tblNotes.id = 1;
Yes, if there is 300 rows of Bar, you'll get 300 copies of the same Notes field, but that's a minor problem.
Form there, you just make txtNote's data source the tblNotes.Notes column. txtNote can certainly exist in the report/page header, and when MS Access generates it, it will only use one row. I'm not sure if picks the first/last row, or random row - never the less since they are all the same, it doesn't matter.