A DatePicker control in a form can remove a lot of uncertainty and mistakes with data entry. e.g. US vs UK, european, etc. formats and also make it easier for the user. Third party controls are available but are now almost unnecessary if you are using Bootstrap (v4 onwards).
Just change the TextMode attribute of an asp:TextBox:
We frequently need to ensure only numbers are entered via a Text Box control. Many 3rd party vendors sell contols that do this but that sometimes means buying the suite or that they can’t be styled to match your website. You can do this quite easily using a standard TextBox control and a RegularExpressionValidator.
In asp.net, database connection strings that have been saved in the web.config file can be retrieved using the WebConfigurationManager.
You can use the WebConfigurationManager in the Page Load event of each page, strore it in a variable, then use the variable whenever you need to talk to the database in that page. But instead of going to get it in every page just do so once when the application starts…
In your Global.asax file create a public variable in which to store the connection string:
Public Shared connString As String
In the Application_Start procedure set it like this:
Web.Configuration.WebConfigurationManager.ConnectionStrings("name of you connection string in your web.config").ConnectionString
To get and use the variable, as it is declared in Global.asax, prefix it with the class name:
One way of getting the ID of the row you just inserted into a table would be to run another sql statement following the insert one. Use an aggreagate statement something like SELECT MAX (CusID from tblCustomers.
You can also get it using the insert statement with the OUTPUT clause…
INSERT INTO tblCustomers (FirstName, LastName) OUTPUT INSERTED.CusID VALUES (‘Fred’, ‘Bloggs’)
(Assuming CusID is the primary key field in the table.)
If you’re running the insert in an application, the command needs to ExecuteScalar rather than just Execute…
I normally work in asp.net so use asp:TextBoxes frequently to capture data input to a database. With the best intentions I guess how many characters the user will need to enter and make the field in the database able to hold that many characters. I may also be limited by the spacing on the form. Especially in “Notes” text boxes a user then wants to enter a life story! The TextBox lets them type what they want but the database doesn’t store it all and when they read the record they find their typing has been cut off.
This jQuery script helps by not letting them type (or paste) too much.
At the top of your page (in the head section perhaps), if you haven’t already got a link to jQuery, add one.
Add a link to the MaxLength script.
For most Access applications that are created for end users (as opposed to yourself), you don’t want the user to be able to go to Design View. This post specifically deals with the right click or shortcut menu.
If you right click on a form one of the menu items is Design View. You can show no menu at all on all forms in the database or on a form by form basis.
Remove shortcut menu completely
From File, Options, choose Current Database on the left, scroll down to the Ribbon and Toolbar Options and untick Allow Default Shortcut Menus.
Remove From Specific Forms
Change the Shortcut Menu property of the form to No.
Create a Custom Shortcut Menu
Add a Reference to the Microsoft Office15.0 / 16.0 Object Library. (In the VBA Code window, choose Tools, References.)
Create a new Module (Insert, Module) and copy and paste this code. DO NOT paste into a form or report module.
Public Sub CreateRightClickBar()
'Run this once only.
Dim cmbRC As CommandBar
Dim cmbButtonCopy As CommandBarButton
Dim cmbButtonCut As CommandBarButton
Dim cmbButtonPaste As CommandBarButton
Dim cmbButtonClose as CommandBarButton
Dim strBarName As String
strBarName = "CustomRightClick"
On Error Resume Next
On Error GoTo 0
Set cmbRC = CommandBars.Add(strBarName, msoBarPopup, False)
Set cmbButtonCopy = cmbRC.Controls.Add(msoControlButton, 21)
Set cmbButtonCut = cmbRC.Controls.Add(msoControlButton, 19)
Set cmbButtonPaste = cmbRC.Controls.Add(msoControlButton, 22)
Set cmbButtonClose = cmbRC.Controls.Add(msoControlButton, 1567)
Set cmbRC = Nothing
Set cmbButtonCopy = Nothing
Set cmbButtonCut = Nothing
Set cmbButtonPaste = Nothing
Set cmbButtonClose = Nothing
In the Immediate Window (Ctrl + G) type the name of the procedure (CreateRightClickBar) and press Enter.
Back in Access Options you will now see your new Shortcut Menu Bar is available.
As previously, you could bypass this and apply the menu to each form individually via the form’s Shortcut Menu Bar property. (Ensure the Shortcut Menu property is set to Yes.)
You only need to run the code once to create the menu bar so you don’t need to save the code or the module. You should also remove the reference to the Microsoft Office 15.0 / 16.0 Object library.
For most users, the ability to right click on a form and close it, rather than navigating to the cross to close the form is a great time saver. Copying and pasting is obviously so too. So in most cases this code is sufficient, but it’s possible to find the ID’s of other button in the Microsoft Office Library (21, 19, 22, 1567) to include in the menu – but that’s for another time!
When using a SQL Server backend, if you get a “Write Conflict” message when editing data, try adding a field of data type timestamp to the table. I often just name it “x”. (Remember to relink in Access).
Create a pass through query in Access. Its content should call the sp like this:
Exec spCusInfo 65
The stored procedure will usually need a parameter, in the example, 65 could be the CusID. If sending a string, surround the parameter in single quotes. If there is more than 1 parameter, separate them with commas.
If you execute the query, you will always get the data for CusID=65. So in a button click event or an AfterUpdate event somewhere add VBA code like this: