473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Control Tab key

I have created a data input form. Currently you can use the tab key to move form field to field within the form. the problem I am having is that if the tab key is used after entering information in the last field of the form, the cursor moves to the first field of a new record. this causes a lot of blank records in the table. How can I turn off the tab key so that it does not automatically start a new record.
I have this form set up to be launched from another form so that the new set of data being loaded will pick up the Record Id from the previous form (parent/child relationship). On the data input form I have created a button that will add the proper id to maintain this relationship. When the tab key is used after the last field is populated no record id is carried over. this is why I don't want the tab key to start a new record.
Jan 27 '17 #1

✓ answered by PhilOfWalton

On the "Other" tab of form properties, set the Cycle to "Current Record"

Another useful thing that you can do to stop a tab key going to a control you don't want it to go to is, again on the "Other" tab of the control's properties to set the Tab Stop to "No"

Phil

13 1282
NeoPa
32,556 Expert Mod 16PB
Hi Bruce.

There is an Event for a form called the BeforeUpdate event which has a Cancel parameter. When this parameter is set to True then the update doesn't happen. It's essentially backed-out or cancelled. Also, Access forms are designed to save records once you navigate away from the current record. Essentially, this is what's happening when you navigate beyond the last control for that record on the form.

So, if you want want to avoid going to the next record accidentally, as it were, then I'd suggest two steps :
  1. Instead of navigating to the required record after opening the form as you are doing currently, open the form originally with a filter (or WhereCondition) that specifies only that specific record can be viewed. This is generally good practice anyway.
  2. Put some code in the event procedure for the Form_BeforeUpdate() event that sets Cancel to True unless the button is clicked to indicate the operator chooses to save the record.
    That can be determined by setting up a Private variable (blnOK for instance) to reflect whether it's ok to proceed or not. By default this would always be False, but in the code behind your button you'd set it to True before the save and then False immediately afterwards. That way the Form_BeforeUpdate() event procedure will know that it needs to allow it.
Jan 27 '17 #2
DO you have a sample of the event procedure code? I am not sure how to phrase the code.
Jan 27 '17 #3
PhilOfWalton
1,430 Expert 1GB
On the "Other" tab of form properties, set the Cycle to "Current Record"

Another useful thing that you can do to stop a tab key going to a control you don't want it to go to is, again on the "Other" tab of the control's properties to set the Tab Stop to "No"

Phil
Jan 27 '17 #4
NeoPa
32,556 Expert Mod 16PB
Well Bruce, a very basic template would be something like :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private blnSave As Boolean, blnClose As Boolean
  5.  
  6. Private Sub Form_BeforeUpdate(Cancel As Integer)
  7.     Cancel = (Not blnSave)
  8. End Sub
  9.  
  10. Private Sub cmdSave_Click()
  11.     On Error GoTo ErrorHandler
  12.     If Me.Dirty Then
  13.         blnSave = True
  14.         Call SaveRec(frmMe:=Me)
  15.         blnSave = False
  16.     End If
  17.     Exit Sub
  18.  
  19. ErrorHandler:
  20.     'Error routine here if you want.
  21. End Sub
  22.  
  23. 'SaveRec() Saves the current record on frmMe.
  24. Public Sub SaveRec(frmMe As Form)
  25.     'No error handling here.  Should be handled by calling code if required.
  26.     'This code is a little weird but how saving has been implemented in Access.
  27.     frmMe.Dirty = False
  28. End Sub
I've added in the code for saving a record on a form as the standard Call DoCmd.RunCommand(acCmdSaveRecord) is unreliable in many cases.
Feb 1 '17 #5
MikeTheBike
639 Expert 512MB
Hi

Not sure if I have fully understood this, but wouldn't setting the form's Cycle property (property dialogue, other tab) to 'Current Record' do the job?

MTB
Feb 2 '17 #6
PhilOfWalton
1,430 Expert 1GB
Just what I suggested.

Phil
Feb 2 '17 #7
NeoPa
32,556 Expert Mod 16PB
Hi Phil (& Mike).

Notice that the OP hasn't posted since you first suggested that solution. It may be that he's found it works after trying it and is no longer exercised about the thread. Certainly it's not something I was aware of (Fallible! I know!), but having looked into it, it does seem that it would probably do the trick. I don't have personal experience of it, but according to the Help system it should work just fine.

-Ade.
Feb 3 '17 #8
PhilOfWalton
1,430 Expert 1GB
@NeoPa

Can't believe there is anything that you don't know???

It would be nice if OPs said "thanks, it worked" and close the topic, but perhaps the younger generation aren't so good with their please and thank you as we slightly older folk are.

Phil
Feb 3 '17 #9
MikeTheBike
639 Expert 512MB
Hi Phil

Sorry I missed your first line, I was drawn the second paragraph about the Tab stop. I was expecting just a one liner, but with all the rest going on I assumed it hadn't been mentioned.

Must try harder and pay attention!

MTB
Feb 3 '17 #10
Thank you, this does the trick.
Feb 3 '17 #11
Thank you.
Sometimes I do not know where to get started with code.
I cannot wait to try this.
Bruce
Feb 3 '17 #12
I enjoyed the banter. I found that setting the control to current record, when you use the button to add another record you loose visibility of what was already entered. So I added a read only query that would display all previous data entered that is related to the parent record. Thus the user can check what they input to avoid duplication of records or blank records.
Thank you again to all of you!
Feb 3 '17 #13
PhilOfWalton
1,430 Expert 1GB
Our pleasure

Phil
Feb 3 '17 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
GaryTexmo
by: GaryTexmo | last post by:
In my last insight, http://bytes.com/topic/c-sharp/insights/909141-object-scaling-varying-resolutions, I talked about scaling objects to a form's size so that it would always draw with the correct...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.