Format a field so it auto populates as a value without dashes from a value with dashes, Access 2013 - ms-access

I have two fields, SSN and ID#. The SSN is entered with dashes and the ID# field is the SSN number without dashes, used in other places of the database. These fields have been manually entered. I would like to automate the process so after a value has been entered in the SSN field (with dashes) it will automatically display in the ID# field without dashes. I can get this to work sort of but it is still slightly manual. If create a lookup for ID
SELECT [Table1].[ID#], [Table1].[SSN] FROM Table1;
this displays all of my entered SSNs without dashes in the drop down but I still have to select them from the drop down. To get the dropdown to update with new SSNs I have to refresh before I can select the newly added value in the ID dropdown. I was able to do this by creating the lookup for ID then I set the input mask for SSN. This is still a manual process and allows for error.
I am sure this is very easy but I am unable to find it. I would like the simplest approach possible. Any help/example is greatly appreciated. Please assume, I know next to nothing about Access. Thank you.

#June7
It's a very simple function. Replace([fieldname], "-", ""). Google it for more guidance. – June7 yesterday
Use that expression in VBA procedure (probably the SSN AfterUpdate event) to set the value of field. However, that is not really necessary. Can just use the expression in query or textbox to display SSN without dashes whenever needed. –

Related

Lookup tables displaying number instead of text [duplicate]

I am trying to create a report putting a field called contact which has the name of a person. This name is linked directly to another table where I keep all the contacts.
For some strange reason, when I include this name (which in query view displays as the name of the contact), instead of the name appearing, the unique ID number is shown on my report.
As mentioned in the article cited in the above comment, you can use a Combo Box control on your report to do the lookup for you. To see how this can be done, create a new report based on the table containing the lookup field, then drag and drop that field onto the report. That will create a Combo Box control with properties that look something like this:
Row Source: SELECT [Clients].[ID], [Clients].[LastName] FROM Clients;
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
You could use a similar Combo Box control on your actual report to display the client's name rather than their numeric ID value.
Another alternative would be to change the Control Source of the report's Text Box control to have it do a DLookUp() on the table. If the lookup field is named [client] then changing the Control Source of the Text Box to something like
=DLookUp("LastName","Clients","ID=" & [client])
would also work.
I wanted to add to the great answer by Gord:
When using a "web" database (started in Access 2007 I think), you cannot change a report's fields to ComboBox style, nor can you use DLookUp(). (web databases lack a ton of features)
The workaround for this, if you want to create a Web-Report that uses lookup fields, is to create a Web-Query first based on your Web-Table (all the Web-* stuff has a www planet icon over the logo, if you create a new Web-DB in Access 2007+ you'll see what I mean)
So, instead of Table -> Report, you'll have to do W-Table -> W-Query -> W-Report.
Then, the only thing you need to customize to get the data right is the W-Query. Start by trying to reproduce the look in the query to match what you want users to see in the report. Note that here in the query, lookups will work fine (instead of the unique ID's, you get field names like you want). However, this will not carry over to the report. To do that, you gotta get the actual text field name you want into the query:
You should already have one table in your query; start by adding the table that your first lookup field points to. For example, the table I want to print is called Stock_Boards, and it has a lookup field called PCBID_lookup that points to the table Stock_PCBs.
Since you're using lookup fields, there should already be a relationship line between the two tables when you add the second one. If there isn't, something has gone horribly wrong.
Now, see how that line connects two fields on the two different tables? For example, I've got my PCBID_lookup field on my Stock_Boards table, which connects to the ID field on my Stock_PCBs table. If I created a report from this now, PCBID_lookup would be a number, a number that correlates to the ID of a record on Stock_PCBs.
To fix it, I will add the name field I want to show up on the report. In my example, that happens to be a Part Number, rather than the ID. I add the PartNumber field from my Stock_PCBs table to the query, and remove the PCBID_lookup field of the Stock_Boards table from my query.
Since PartNumber is what I want to show up on my report, it effectively replaces the original field (PCBID_lookup)
Repeat for all lookup fields you want in your report.
I had 1 more: I removed the Status field of the Stock_Boards table (which was an ID/Lookup) and added the 'Status' field from the Status table (which was the actual text name)
When finished, your query should look exactly how you want the data to appear, without any special tricks or asking Access to do something unnatural. Save your query, and create a web-report from it. Done!

Form fields show '#DELETED' after running 'acCmdSaveRecord'

I've been having an issue today where one of my forms is filling all fields with "#DELETED" after I save the record. This wasn't happening three hours ago, and it seems to have started without me changing anything on the form itself. The record is still being saved, and there are no "#DELETED" entries in the table at any point. I am using the following code to open the form:
DoCmd.OpenForm "frmPoster", , , , acFormAdd
This is the code that saves it:
Call DoCmd.RunCommand(acCmdSaveRecord)
I am using Access2010 with SQL Server and VB. As I said, the really confusing part is that seemingly nothing has changed about this form that would be causing this. It worked, and now it doesn't. Any ideas?
Also, if you want any more information regarding the issue, I will be happy to provide.
I've used SQL with Access a lot and had some similar problems, I'd advise unless you have already to make sure you have a timestamp field in the SQL data, and also do a me.requery in VBA after the update so it re-selects the record.
I ran into the same problem yesterday - as soon as I try to save the record, all fields turn to #Deleted. Tried to resolve for hours - no luck.
I use Access 10 / 2016 and MySQL ODBC connector 5.3.
I narrowed it down to one specific field with a 13 digit number.
The datatype for the field was varchar. When I enter any value that does not match the required format (as checked by VBA), and then delete or edit it and move to the next field, the form refuses to create the UserID upon save and gives #Deleted.
If I skip this field during data entry, then the form creates the UserID (Primary Key) and saves. Also, if I enter a value that matches the field criteria first time round, the form generates the Primary key and saves.
As suggested somewhere I changed the datatype to numeric 14,0 for this field.
This did not help.
I tried to requery the form after saving as suggested but since the record is deleted, it simply displays blank fields.
So here is my hack:
1. On the "On Enter" event of the first field in the form, run code to set temporary values in each of the required fields, for example:
First I created an unbound hidden field with default value of "No". Then:
If Me.NewRecord=True and Me.FormPreppedYN="No" then
Me.txtFirstName="Hello"
Me.txtLastName="There"
Me.IDNr=123
Me.Ref="ABC"
Me.Dirty=False
Me.txtFirstName=""
Me.txtLastName=""
Me.IDNr=Null
Me.Ref=""
Me.txtFirstName.SetFocus
Me.FormPreppedYN="Yes"
End If
This forces the form to create a Primary key. This happens very quick and the user doesn't notice it. They just enter the data.
This worked reliably every time. I still don't know what causes the error, but this fixes it.

How to match text to a defined numeric value

I have a database that has a bunch of survey data that I would like to work with. For several questions, the values are things like "Very important","Not at all likely" and I want to create a calculated field to assign a numeric value to these responses.
I don't want to replace the responses at all since I am going to have a user fill out a form to append the data set. I do want to have a calculated field that will automatically assign a numeric value to a text response.
I would just use a vlookup or an IF function in Excel to do this, but the problem is that Excel can't handle as much data as Access can. I need to set it up so that all Excel will house is a pivot table from the Access database.
Could anyone please tell me if there is a good way to do this? I am just not sure how to do it.
Create a new table with 2 columns: user_value (text) and numeric_value (number). Get all of the user entered values uniquely from the user entered data table with a query (the sigma symbol gives you a group by query). Put these in your new table and assign a numerical value to them. Then you can create an output query which joins your data to the lookup table and retrieves the numerical value for each user entered value.

A little Access VBA help? Validating against duplication of a non key field?

I am adding a part name to the database using a form, What code do I put behind the Add part button to validate against duplicate part names? (part number is the primary key) I think I need another recordset to search and compare the table but i'm a bit lost, any help would be great.
Private Sub btn_add_Click()
rs_parts.AddNew
With rs_parts
!partrno = lbl_partno.Caption
!Name = txt_name
rs_parts.update
end with
I've discussed my approach to this before, and given an example form for adding a new record.
I use an unbound form to collect the information needed to create the new record, and have it check for duplicates, and present a list of them to the user so the user can decide what to do.
In this case, it sounds like a unique index is in order, so you won't really need to worry about close matches. I would probably still use an unbound form to capture the new value and run the check before even attempting to add it. In that case, I'd just notify the user that it's a dupe.
Should you add a unique index to the part name field?
If you want, you can create a query on your part table with one column for the name and a parameter for the criteria they've entered in txt_name. Then pass the value they entered as a parameter to the query and see if you get any results.

How to look up values from a table in Access

I have an Access database that is used to store basic info in a table such as first and last name. How would I go about adding the functionality to lookup by last name?
Is there a way to type in the last name and then hit like F12 or something like this? Can someone please point me in the right direction or provide me a link?
SELECT tblPatient.LName AS [Last], tblPatient.FName AS [First]
FROM tblPatient
WHERE (((tblPatient.LName)=[Enter Last Name]));
How do I tie this into my form now?
I'd suggest you create a form, with a textbox 'search' at the top, then either a listbox or subform below to display results.
The listbox record source would be:
SELECT tblPatient.LName, tblPatient.FName
FROM tblPatient
WHERE tblPatient.LName LIKE Forms!myForm!search & '*';
You can either add a Search button, which requeries the listbox, or do the requery via the Change event of the search textbox. The later may be slow if you have a large number of records; if that's the case, you could check that at least 3 (?) characters have been entered before calling the requery.
You just need to create a query in which you put =[?] as the "last name" value.
When you open that view, you'll be asked to type in a lookup value for that field.
Not sure if this is what you are trying to archieve, though...
This is probably a bit overkill for what you want to do, but I assume that you want to perform a search by last name. You should be able to glean the information you need from this article:
Build a search criteria form
http://www.everythingaccess.com/tutorials.asp?ID=Build-a-search-criteria-form
You can create queries in Access if the user you're targeting with the searchability has Access themselves.
From the main Access UI (assuming Access 2007), go to the Create tab and then select the "Query Wizard." Here is an article on the subject.
Otherwise you can create a program and connect to the MDB/ACCDB file running the query programmatically.
Seeing you wish to look up a name and populate the form based on the name selected, I suggest you need a combobox. There is even a wizard for doing exactly what you want. To start, you will need a form bound to a table or query, that is a form with a Record Source.
Add a combobox to your form
Select :
Find a record on my form based on the value I select in my combobox
Select the ID (primary key), Last and First name fields.
Access will display an example, suggesting that you hide the Key (id) column. Accept this.
Choose a name and finish.
There are a few other small things that could be done for neatness, but you will end up with a form that find the record you want. In addition, the combo will autocomplete if you type in a few letter.
If this is an mde, which your subsequent post seems to suggest it is, there is little you can do wuth out the original file. However, you could try opening the database while keeping the shift key held down and see if that allows you to edit. If you cannot get the original and the shift does not work, you could try rescuing the data, if it, too, is stored in this file.