473,785 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subform Controls Disappear When Edits/Deletions/Additions = No

55 New Member
I'm using Access 2003 on a Windows XP O/S.

I've made two copies of Form1 so that there're are 3 forms:

1) Form1
2) Form2
3) Form3

Essentially, they all write to the same Table1.

Each of these forms is reached by clicking one of three links on my switchboard:

1) New Record --> Form1
2) View All Records --> Form2
3) Edit Records --> Form3

I thought I could just make the following modifications to each form's properties and make each form function in a different way:

1) Set Form1 to "Data Entry" and remove navigation controls.
2) Set Form2's Recordset Type = Snapshot OR Edits/Deletions/Additions = No.
3) Leave Form3's properties alone. Possibly add a record search feature so that only one record is edited at a time and maybe set a user/password so that records aren't edited without authorization.

Alas, I've got a few problems.

A) Even though I set Form1 to "Data Entry," the first record is totally blank (i.e. no controls show up at all). There are no records in the underlying Table1. Now, I know that controls usually disappear when there are no records in the underlying table and/or the properties are set to Edits/Additions/Deletions = No and/or Recordset Type = Snapshot.

Question: What's the best way to set up a data entry form and/or to keep the controls visible regardless of whether there are records in the underlying table?

B) What's a good way to set up an editable form so that access to the records isn't too liberal? Is there a good user/password code that I can use? Is there a way to set up a query or search parameter so that only a single record is opened according to the AutoNumber (i.e. the file number) that the user wants?


Thanks in advance for all your help.
-Benny
Nov 5 '07 #1
8 4009
BASSPU03
55 New Member
Question: What's the best way to set up a data entry form and/or to keep the controls visible regardless of whether there are records in the underlying table?
OK, so I've managed some headway into this problem and this is how I worked around the "Edits/Deletions/Additions" and "snapshot" dilemmas.

The only way I know to keep Form1 as a data entry form without sacrificing the visibility of the controls is to not mess with "Edits/Deletions/Additions" and Recordset Type properties at all. Instead, I just set the Data Entry property to "Yes" and removed the navigation controls. Since the navigation controls are gone, it's now not possible to simply click the " >* " button for a new record. So, after one is done entering data for one record, he/she can click a command button labeled "Add New Record" that essentially closes Form1 and opens it again, but it's now refreshed. The code I used for it is essentially the same code I used to close my switchboard when I clicked "OK" to move on to the next switchboard "Main Menu." Here's that code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNewRecord_Click()
  2. On Error GoTo Err_cmdNewRecord_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     DoCmd.Close acForm, "frmNewResource"
  8.     stDocName = "frmNewResource"
  9.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  10.  
  11. Exit_cmdNewRecord_Click:
  12.     Exit Sub
  13.  
  14. Err_cmdNewRecord_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdNewRecord_Click
  17.  
  18. End Sub
  19.  
I put:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, "frmNewResource"
  2.  
before

Expand|Select|Wrap|Line Numbers
  1. stDocName = "frmNewResource"
  2. DoCmd.OpenForm stDocName, , , stLinkCriteria
  3.  
instead of after it like I did for the switchboard and it works just as if I were opening up a blank new form.

I'm still stuck on finding a code that'll allow me to pull up an individual record by AutoNumber for editing purposes. Any help would be greatly appreciated.

Best,
Benny
Nov 5 '07 #2
missinglinq
3,532 Recognized Expert Specialist
I’ve got to tell you, Benny, I’ve gotten a headache from trying to follow all the ins and outs of what you’ve already tried in your database! So I’m going to start off with some very basic advice: Keep It Simple! When tackling a relatively big job like this, take a pen and apiece of paper, and write down a very simple outline of the problem. In this case you need:
  1. SwitchBoard Form
  2. New Record --> Form1
  3. View All Records --> Form2
  4. Edit Records --> Form3
Next, and this is the important part, take the problems on one at a time! Don’t go harrying off in three or four different directions, working first on one form, then another, then a third, never getting any of them to work properly, and becoming mired down more and more as you go along. This particular problem isn’t, believe it or not, all that complicated!

To begin with, you don’t need four forms, you only need two! A SwitchBoard form and a form to display your records. Stop and think about it; what you’ve called Form1, Form2 and Form3 are really the same form! They all hold the same data! You simply want the form to handle that data in different ways, depending on circumstances, so that’s what you should do, have one form but make it operate in different ways, depending on your needs. I’ll give you most of what you’ll need to accomplish this task, only holding off, for now, on the question of limiting who has the ability to edit/delete records. After you get everything else up and working, you can tackle that.

While it’s true that you can control whether records can be added or edited or deleted or even viewed, thru the Properties box for a given form, you can also do this by the manner in which you open the form, and that’s what I’ll demonstrate here.

The SwitchBoard form is where you’ll navigate, not between three almost identical forms, but rather between the three instances of the same form. Let’s start with this form, frmSwitchBoard:

You’ll need three command buttons to open the data form in the appropriate mode, cmdNewRecord, cmdViewAllRecor ds and cmdEditRecords.Here’s the code for these buttons.

This button will open the data form so that new records can be entered. You can add one, or more than one, new record, but you can't navigate to an existing record! Opened in this mode (acFormAdd) the Access nav buttons will only move to a new record. After frmNewResource is opened frmSwitchBoard is closed.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNewRecord_Click()
  2. On Error GoTo Err_cmdNewRecord_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "frmNewResource"
  7.     DoCmd.OpenForm stDocName, , , , acFormAdd
  8.     DoCmd.Close acForm, "frmSwitchBoard"
  9.  
  10. Exit_cmdNewRecord_Click:
  11.     Exit Sub
  12.  
  13. Err_cmdNewRecord_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_cmdNewRecord_Click
  16.  
  17. End Sub
This button will open the form in ReadOnly mode. You can view all records but you can't add/edit/delete records; Access disables these options when the form is opened using acFormReadOnly.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdViewAllRecords_Click()
  2. On Error GoTo Err_cmdViewAllRecords_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frmNewResource"
  8.     DoCmd.OpenForm stDocName, , , , acFormReadOnly
  9.     DoCmd.Close acForm, "frmSwitchBoard"
  10.  
  11. Exit_cmdViewAllRecords_Click:
  12.     Exit Sub
  13.  
  14. Err_cmdViewAllRecords_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdViewAllRecords_Click
  17.  
  18. End Sub
This final button allows the records to be edited or deleted. The OpenArgs parameter ("Edit Only") is used in this OpenForm command. When accessed in the Form_Load event of frmNewResource, it tells Access not to allow new records to be added and allows the combobox cboResourceID to be visible. This dropdown box will be used to go to a given record for editing/deletion, and will only be visible when the form is opened in edit mode..
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEditRecords_Click()
  2. On Error GoTo Err_cmdEditRecords_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frmNewResource"
  8.     DoCmd.OpenForm stDocName, , , , , , "Edit Only"
  9.     DoCmd.Close acForm, "frmSwitchBoard"
  10.  
  11. Exit_cmdEditRecords_Click:
  12.     Exit Sub
  13.  
  14. Err_cmdEditRecords_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdEditRecords_Click
  17.  
  18. End Sub
  19.  
Now, for your data form, frmNewResource:

First, if you haven't already done so, create your data form frmNewResource based on your table/query, including all the fields you want displayed. Leave all of the form's properties at their Default settings! Don't mess around with the AllowAdditons, AllowDeletions, AllowEdits and Data Entry; the mode used to open the form will take care of these things. Then simply:


Add a combo box to your form. The Combobox Wizard will pop up

Select "Find a record based on the value I selected in my combobox."

From the table/query the form is based on, click on the field you're searching by (your ID field) to move it to the right side.

Hit Next.

Size the column appropriately.

Hit Next.

Name the combobox cboResourceID.

Hit Finish.

Now you can drop the combobox down and scroll down to the item to search by, or you can start to enter the item, and the combobox will "autofill" as you type. Hit <Enter> and the record will be retrieved.

This code, thru the use of OpenArgs, tells Access to not allow new records to be added when the form is opened for editing/deleting of records. It also allows the combobox we made, which will be used to retrieve a given record, to be visible.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. If Len(Nz(Me.OpenArgs, "")) > 0 And Me.OpenArgs = "Edit Only" Then
  3.     Me.cboResourceID.Visible = True
  4.     Me.AllowAdditions = False
  5. Else
  6.     Me.cboResourceID.Visible = False
  7. End If
  8. End Sub
  9.  
Give this a try now, keeping a few things in mind. First, try to get the code working as it's given here. If you have problems, post back here telling us about it. Don't go changing this, changing that willy nilly and then posting back when it doesn't work; this will just end up confusing you and the people here who are trying to help you. This is always a good policy when trying to implement code someone's posted. The exception, of course, would be when you're simply replacing generic control names with your own actual names.


Next, create your frmSwitchBoard with its buttons and code and your frmNewResource with it's combobox.


Finally, test things one at a time. Make sure your data form is behaving properly. Make sure the combobox is working correctly, retrieving records as it should. And finally, test out each form opening mode to make sure that they're behaving properly.



I've spent a fair amount of time hacking this problem, and it's all working on my end, but sometimes things do get copied/pasted incorrectly going from Access to here on the forum. So if you have any problems, post back here and be patient. I'll be checking back fairly frequently tomorrow (well, today actually; it's about 0400 hours here) and I'm sure other people will be looking in as well.


Good luck!


Linq ;0)>
Nov 6 '07 #3
BASSPU03
55 New Member
All but one thing is working fantastically as far as I can tell. My most sincere gratitude....

First the problem, then the optional read:

PROBLEM

Now you can drop the combobox down and scroll down to the item to search by, or you can start to enter the item, and the combobox will "autofill" as you type. Hit <Enter> and the record will be retrieved.
This works very well, but, after hitting <Enter>, I can't get the record to change. I can tell that it doesn't change at all because a bound AutoNumber textbox in the upper right-hand corner of the window stays at '85,' for example, even if I attempt to navigate to '86.' This AutoNumber, although repetitive in the "Edit Records" version of my form, is useful when the search ComboBox is invisible in the "Create New Record" and "View All Records" versions.


OPTIONAL READ

Stop and think about it; what you’ve called Form1, Form2 and Form3 are really the same form! They all hold the same data! You simply want the form to handle that data in different ways, depending on circumstances, so that’s what you should do, have one form but make it operate in different ways, depending on your needs.
My mind thinks this way but it doesn't possess the Access knowledge to get it to function accordingly. : ) So, instead, I come up with (usually inefficient) workarounds to keep progressing. My time on this project is very limited, so I'm trying to keep going without having to post every single question. And, please, let's not get started on normalization!

First, try to get the code working as it's given here. If you have problems, post back here telling us about it. Don't go changing this, changing that willy nilly and then posting back when it doesn't work; this will just end up confusing you and the people here who are trying to help you.
According to your codes, my switchboard kept closing after clicking one of the three linking buttons. I'd rather keep the switchboard open underneath. I know you said not to change it, but I've learned enough to know that removing the DoCmd.Close line will keep my switchboard open. After removing it, it works just fine. Please don't hate me!

I've spent a fair amount of time hacking this problem, and it's all working on my end, but sometimes things do get copied/pasted incorrectly going from Access to here on the forum. So if you have any problems, post back here and be patient.
You should be paid by commission. Really. I can't thank you enough for actually reproducing my scenario and posting very thorough codes and instructions. I am very grateful, but please don't give yourself headaches over my issues!

I will make future posts more concise and limit them to single problems. Trust me: I don't want to be the guy that's lambasted for improper forum etiquette. These types of forums are a bit more demanding than most and it takes some getting used to. Nonetheless, I understand the purpose. Not only is this my first forum with strict guidelines, but it's also the first one whose rules are actually enforced.

If there's any place I can offer positive feedback for your efforts, please let me know.

Sincerely,
Benny
Nov 6 '07 #4
BASSPU03
55 New Member
I don't mean to sound impatient, but I haven't heard anything in a week. Missinglinq: Thanks again for the combobox code to search editable records by keyword. On a slightly-related note, I commented that I couldn't get the combobox search function to change records. I found a code that does the trick:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboResourceID_Change()
  2.     Dim strSearch As String
  3.     strSearch = Me.cboResourceID 'whatever the name of your combo is
  4.     Me.AutoNumber.SetFocus
  5.     DoCmd.FindRecord strSearch, acEntire, , acSearchAll, , acCurrent
  6. End Sub
  7.  
It's in the OnChange event and works like a charm.

However, there's a problem. I noticed that after I entered all of your codes, my print preview feature only successfully previews the first record. When I change records and click Print Preview, the corresponding report appears blank (i.e. with empty fields). Any idea why? Could it be because of the edit limitations your code imposes on the form? This is the code for my print preview button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintPreview_Click()
  2.     Dim strWhere As String
  3.  
  4.     If Me.Dirty Then    'Save any edits.
  5.         Me.Dirty = False
  6.     End If
  7.  
  8.     If Me.NewRecord Then 'Check there is a record to print
  9.         MsgBox "Select a Record to print"
  10.     Else
  11.         strWhere = "[AutoNumber] = " & Me.AutoNumber
  12.         DoCmd.OpenReport "Administration", acViewPreview, , strWhere
  13.     End If
  14. End Sub
  15.  
Thanks.
Nov 13 '07 #5
missinglinq
3,532 Recognized Expert Specialist
Once again we need to work on one problem at a time! In fact, I think I'm going to split off the problem of having a main form the editable with read-only subforms. That way the title will reflect the current problem more acurately.

Try modifying this code:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdPrintPreview_Click()
  2.      Dim strWhere As String
  3.  
  4.      If Me.Dirty Then    'Save any edits.
  5.          Me.Dirty = False
  6.      End If
  7.  
  8.      If Me.NewRecord Then 'Check there is a record to print
  9.          MsgBox "Select a Record to print"
  10.      Else
  11.          strWhere = "[AutoNumber] = " & Me.AutoNumber
  12.          DoCmd.OpenReport "Administration", acViewPreview, , strWhere
  13.      End If
  14.  End Sub
  15.  
to this:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdPrintPreview_Click()
  2.      Dim strWhere As String
  3.  
  4.      If Me.Dirty Then    'Save any edits.
  5.          Me.Dirty = False
  6.      End If
  7.  
  8.      strWhere = "[AutoNumber] = " & Me.AutoNumber
  9.          DoCmd.OpenReport "Administration", acViewPreview, , strWhere
  10.      End If
  11.  End Sub
  12.  
You don't need to check for a new record with

If Me.NewRecord

because there won't be any! If there was a new record, it's no longer new, because you saved it with

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

So try the code with this and see what happens. And as I said, I'm going to split off the last problem.

Linq ;0)>
Dec 2 '07 #6
BASSPU03
55 New Member
I tried the code but it still brought up an empty report. Funny thing is that I tried creating a form print preview command button using the wizard and the report still came back empty (i.e. report's there, but the fields are empty, even though the record isn't).

I think this starting happening when I added the New Record, View All Records, and Edit Records codes that you offered earlier in this thread.
Dec 3 '07 #7
sierra7
446 Recognized Expert Contributor
I tried the code but it still brought up an empty report. Funny thing is that I tried creating a form print preview command button using the wizard and the report still came back empty (i.e. report's there, but the fields are empty, even though the record isn't).

I think this starting happening when I added the New Record, View All Records, and Edit Records codes that you offered earlier in this thread.
Is you Print Preview still blank if you navigate back to a previous record ?

If not then add a DoCmd.RunComman d acCmdSaveRecord at Line 3 to force a 'save' because it sounds as though the report is not finding any data.

You could also 'comment out' the criteria (put an apostrophy after acViewPreview and before the comma) which should list all your data, just to test the report is working. If this would result in too much date then hard-code the criteria to a particular value or range.

Interesting reading otherwise!
Dec 3 '07 #8
BASSPU03
55 New Member
Sierra7, thank you so much for your suggestions! Unfortunately, none of them worked. However, I'm optimistic because I created a new form using the wizard and the report is working again, even when I change to a new record. I think I may have tinkered a bit too much with the DB and the report no longer reflected the tables' values. I'll keep my fingers crossed and will post back if it comes up again. Thanks again!
Dec 3 '07 #9

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

Similar topics

4
2489
by: Deano | last post by:
If I create 2 or more records in my subform and I then delete the main record, then all the controls on my subform disappear. Yet if there is only one record in the subform then it gets deleted ok and the controls are still there ready to await further input. Further info; Cascading Deletes are on. The subform Cycle property is set to Current Record.
6
3948
by: Sally | last post by:
I need to be able to click in a subform and run code but at the same time I need to be able to scroll the records without running the code. I tried coding the Enter event of the subform control but when I try to scroll the records the code runs. The subform is continuous; all the controls are on one line and the detail section is not exsposed above or below the controls. I tried coding the detail Click event but nothing happened. I tried...
10
1672
by: MLH | last post by:
I have a form, one of about 20 editing forms I created last week. All were created pretty much the same way, used the column wizard just to throw everything from the source table/query up there. Then I modified from there, adding buttons 'n whatnot. I cannot see any controls on one of the 20 forms in form view. They're all there in design. None have visible property set to False. The controls are just not showing up. No matter how many...
2
1737
by: Welie | last post by:
I apologize if this is a faq. I searched for about 45 minutes and didn't find a good answer but there are many matching posts. I have a form which is based on a simple query to a linked table. The data is set to no edits,additions,deletions,dataEntry. If the form is open, but the linked table is opened seperately in design mode, than a message appears saying "the table is already opened exclusively by another user". Which makes perfect...
10
2975
by: Ami | last post by:
Hello everyone, I have developed a small access application and now I need to lock my forms against unwanted edits. I have used the code by Allen Browne I found here http://allenbrowne.com/ser-56.html and it works great, but I need to unlock and lock my main form and subform separately, using two different buttons.
4
1637
by: BerkshireGuy | last post by:
I have a form, with a subform that changes AllowsEdits,AllowAdditions, etc depending on who is coming in. This is done by using the OpenArgs and is working fine. However, if the user is restricted (meaning no additions, deletions, etc) they can still click on a combobox, just nothing happens. A couple of additional thoughts: 1) Using enabled=false is not an option because the user doesnt like
4
8850
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form which allows me to edit the record in the subform. What I want to happen is for subform with the new edits to be updated on the main form when I close the popup. I'm sure this is a very small bit of code in the the 'On close' event for the popup...
7
6606
by: robtyketto | last post by:
Greetings, I have a main form. Upon filling in a combo box it then displays a subform (based on a query that uses values in the combo box on where clause) THe subform has the paramater Data Entry = 'No' as I want users to see all existing records and all additions/deletions and edits. However I want to move to the last record to default, allowing the user to add a record without navigating themselves to the last record. A popular...
2
2082
by: MLH | last post by:
I have an A97 form with Allow Edits, Allow Deletions and Allow Additions properties set. Scrolling through records will eventually take me to the end of the records and one more PgDn will take me to a new record. I also have a cmd button on the form to take me instantly to a new record. There are 2 controls on the form I would like disabled whenever I'm at a new record. I want them enabled at all other times. Which event property would...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.