473,432 Members | 1,659 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,432 software developers and data experts.

How to make a newly-added record show up in an existing form?

sueb
379 256MB
In my IURs database (ADezii, you probably still have a good back end for this), I don't want my users to be able to change the Chart Number field, but I do want them to be able to add new ones. (In a later incarnation, I want to add a module to allow a controlled modification, but currently I have that field Locked because users have inadvertently changed it instead of searching on it.)

I have a form that allows the addition of just a chart number, and I want the currently-open form (based on chart numbers) to reflect the addition without requiring the user to exit the form and re-enter it.

I have a Requery statement where I think it should go, but it doesn't seem to be doing what I want.

Here's the code OnClick for the "Add New Chart #" Control button on the main form ("Patient/IUR Overview"):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_New_Chart_Click()
  2. On Error GoTo Err_Add_New_Chart_Click
  3.  
  4.     Dim stFormName As String
  5.  
  6.     stFormName = "Patients_Add_New"
  7.     DoCmd.OpenForm stFormName, acNormal, , , acFormAdd
  8.  
  9. Exit_Add_New_Chart_Click:
  10.     Exit Sub
  11.  
  12. Err_Add_New_Chart_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_Add_New_Chart_Click
  15.  
  16. End Sub
  17.  
This brings up a tiny window with just the Chart Number as a field. (The user must exit this field with the TAB key, but I wish it would allow the RETURN key to behave in the same way. Any tips there would be appreciated, too.)

Once the user has successfully entered a new chart number, the "add" window closes itself. However, the new record is not available in the main window unless the user exits the window and re-opens it.

Any hints?
Feb 16 '11 #1

✓ answered by NeoPa

I think your instructions were aimed at another problem Sue. I've responded to that in the relevant thread (after moving it from here where I pasted it in error, before I realised this wasn't the correct thread). I managed to find the problem in your database that is described in this thread, and my findings are detailed below.

The more modern method of calling the Save for the record is :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunCommand(Command:=acCmdSaveRecord)
The .DoMenuItem form has been superceded (It was always very kludgy and hard to read - as well as hard to write of course).

I found the code in your ChartNum_AfterUpdate() procedure when looking at the form [Patients_Add_New]. This is called from the form [Patient_IUR_Overview].

The changes I made to fix your problem were :
  1. The form itself was saved with a value in the .Filter property. This was removed.
  2. The control [ChartNum] was updated to change properties :
    1. .EnterKeyBehavior set from "New Line in Field" to "Default". This was ensuring the default control on the form was not being triggered as it would otherwise have been.
    2. .ScrollBars set from "Vertical" to "None". This just looked wrong.

It seemed to work fine after I'd made those changes. I assume it's what you're after.

21 2531
ADezii
8,834 Expert 8TB
Try
Expand|Select|Wrap|Line Numbers
  1. Forms!Patient/IUR Overview.Requery
in the Close() Event of the Chart# Form.
Feb 17 '11 #2
NeoPa
32,556 Expert Mod 16PB
I would use either of :
Expand|Select|Wrap|Line Numbers
  1. Forms![Patient/IUR Overview].Requery
  2. Forms("Patient/IUR Overview").Requery
The embedded space will otherwise confuse the compiler/interpreter.

As for using the enter key, I would suggest another control on your form (could be as simple as an OK button), that could be invisible if you prefer, which has its .Default property set to True. This will ensure the focus leaves the main control and therefore the changed value will be applied.
Feb 17 '11 #3
ADezii
8,834 Expert 8TB
@NeoPa: Thanks for catching the Space, never caught it! (LOL).
Feb 17 '11 #4
sueb
379 256MB
That's really interesting, NeoPa! So if I simply place a non-Visible button on my form, and set its .Default property to True, then it's the thing that will catch the return key?

I'm going to try that and post back how it works--thanks!
Feb 17 '11 #5
sueb
379 256MB
So it turns out I still had on the "add" form a left-over, unused, invisible button that no longer has any code attached to it. I set its .Default property to Yes. Pressing enter after typing a new chart number in the form's field seemed to do nothing except clear the field; it did not close the form (although it turns out that it did add the new record), and when I clicked the window's standard exit button to close it, I got an error: "Run-time error '2501': The close action was canceled." The debugger stops on line 6 of the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ChartNum_AfterUpdate()
  2.     stDocName = "Patients_Add_New"
  3.     If ReadWrite Then
  4.         DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  5.     End If
  6.     DoCmd.Close acForm, stDocName
  7. End Sub
  8.  
Am I making this harder than it needs to be or something?
Feb 17 '11 #6
NeoPa
32,556 Expert Mod 16PB
SueB:
Am I making this harder than it needs to be or something?
Very possibly Sue, but interesting nevertheless :-D

Trying to follow the logic, I keep coming up with bits that don't seem to make sense.

Certainly, the standard effect of updating the value and saving it would be to move to another (New) record. Just as you describe. Also, calling DoCmd.Close, as you do in line #6 (Well done for clearly identifying where the problem occurs by the way - So much easier to work with), from within form closing code anyway, would be expected to throw up this error message (It doesn't make sense to call for the form to close when it's already in the process of closing. If it allowed you to do that the code would process through what it had already done again, eventually ending up in an interminable loop).

I would guess that moving your line #6 to the procedure behind the hidden command button may be what you need, but I would need to see the whole module (I don't imagine it's very large) to know for sure.
Feb 18 '11 #7
sueb
379 256MB
NeoPa, I tried moving that line to the hidden command button, but I couldn't seem to find the right event. Open to me are:

OnEnter/Exit
OnGotFocus/LostFocus
OnClick/DblClick
OnMouseDown/Move/Up
OnKeyDown/Up/Press

I tried the close command in each of the first four events (the window doesn't close, and nothing else happens either, except for the addition of the new record), and the others don't make sense to me.

Here's the code for that form:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub ChartNum_AfterUpdate()
  4. On Error GoTo err_ChartNum_AfterUpdate
  5.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  6. exit_ChartNum_AfterUpdate:
  7.     Exit Sub
  8. err_ChartNum_AfterUpdate:
  9.     MsgBox Err.Description
  10.     Resume exit_ChartNum_AfterUpdate
  11. End Sub
  12.  
  13. Private Sub Form_Close()
  14.     Requery_Open_Forms
  15. End Sub
  16.  
  17. Private Sub Open_New_Patient_Overview_LostFocus()
  18.     stDocName = "Patients_Add_New"
  19.     DoCmd.Close acForm, stDocName
  20. End Sub
  21.  
And really, I can't believe this is this difficult. I just want to keep the user from modifying the chart number, while still allowing her to add new ones. If you have some simpler way to achieve this, I'd switch in a heartbeat!

(oh, and the requery doesn't, but i'll address that in a separate question later)
Feb 23 '11 #8
NeoPa
32,556 Expert Mod 16PB
NeoPa:
I would guess that moving your line #6 to the procedure behind the hidden command button may be what you need
I guess this is what you're referring to Sue. The event you would be looking for then is the OnClick event of the Command Button control itself. The code would look somewhat similar to the following (assuming the name of your hidden control is cmdHidden) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdHidden_Click()
  2.     Call DoCmd.Close
  3. End Sub
BTW. Your posted module tells me you really should look at Require Variable Declaration. This is very important for helping you to avoid easily avoidable errors.

I expect the example code I included in the procedure is actually all you'll need.
Feb 24 '11 #9
sueb
379 256MB
Okay, NeoPa, I put that in the OnClick event, but the window still did not close.

(And thanks for the tip about Require Variable Declaration. This database already had this option set, but one of the other databases I maintain did not, so I set it in that one.)
Feb 24 '11 #10
NeoPa
32,556 Expert Mod 16PB
If I remember correctly, you are simply hitting <Enter> after entering the value in the TextBox control of the form. In this case I would expect the event procedure to fire. The only thing I can think of that might be causing it to fail is if you haven't set the value of the OnClick property of the hidden Command Button (cmdHidden) to the string "[Event Procedure]". This can be done easily from the Properties pane when editing the control on the form.
Feb 24 '11 #11
sueb
379 256MB
No, the OnClick property is set to "Event Procedure". But is it really true that hitting <Enter> is going to be interpreted as a "click" for this button? Is that because the button is the .Default? Is there any check on that, for instance, would the form give you an error if more than one button were set to be the default? Or is that something that Access could handle?
Feb 24 '11 #12
NeoPa
32,556 Expert Mod 16PB
SueB:
No, the OnClick property is set to "Event Procedure".
I assume you mean "[Event Procedure]". This is the default that is set for you from the drop-down list.
SueB:
But is it really true that hitting <Enter> is going to be interpreted as a "click" for this button?
Yes. Indeed it is.
SueB:
Is that because the button is the .Default?
Yes. Absolutely.
SueB:
Is there any check on that, for instance, would the form give you an error if more than one button were set to be the default? Or is that something that Access could handle?
It can never happen. Access automatically resets the .Default property of every other control to False whenever any control is set as the default.

I assume the process is still not working as you expect? If so, you can attach a sanitised copy for me to look at if you like. I'll copy below some instructions for ensuring it's sanitised :

When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
  4. If the database includes any code, ensure that all modules are set to Option Explicit (See Require Variable Declaration).
  5. If you've done anything in steps 1 to 4 then make sure that the problem you're experiencing is still evident in the updated version.
  6. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
  7. Compact the database (Tools / Database Utilities / Compact and Repair Database...).
  8. Compress the database into a ZIP file.
  9. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
Feb 24 '11 #13
sueb
379 256MB
NeoPa, I'll certainly do that today! I have an all-morning meeting starting in a few, so it will be later today.

So I was interested to see that one of your instructions was to compile the database. I've been wondering whether there wasn't something like that in Access, mostly because my collection management seems to have gotten so very slow. Would compiling everything make it run faster? Or is it a different thing from the compiling I'm used to?
Feb 24 '11 #14
NeoPa
32,556 Expert Mod 16PB
VBA is a strange animal Sue. It's technically referred to as semi-compiled. That is to say that there is an element of pre-processing involved, yet there is an interpretation element too. The compilation element is particularly useful for catching the more obvious errors. By obvious I suppose I really only mean those which can be checked around known rules. It can't detect all problems, but only those that break the fundamental rules.

It's also interesting to note that as each separate line of code is interpreted as it's run too, there is an interpretation overhead in time for all VBA code.

Actually, it seems that Access compiles the code automatically in some certain circumstances, but as I'm not exactly which they are, and belt and braces doesn't hurt, I always recommend (and do myself) compiling a project manually.
Feb 24 '11 #15
sueb
379 256MB
Okay, NeoPa, I'm attaching my database's front and back ends in a single zip. The simplest way to reproduce this is to execute the query "ACE_Volumes" from the database window. I hope you are able to find out something!

Thanks for your help.
Attached Files
File Type: zip IURs.zip (4.92 MB, 99 views)
Feb 25 '11 #16
NeoPa
32,556 Expert Mod 16PB
I think your instructions were aimed at another problem Sue. I've responded to that in the relevant thread (after moving it from here where I pasted it in error, before I realised this wasn't the correct thread). I managed to find the problem in your database that is described in this thread, and my findings are detailed below.

The more modern method of calling the Save for the record is :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunCommand(Command:=acCmdSaveRecord)
The .DoMenuItem form has been superceded (It was always very kludgy and hard to read - as well as hard to write of course).

I found the code in your ChartNum_AfterUpdate() procedure when looking at the form [Patients_Add_New]. This is called from the form [Patient_IUR_Overview].

The changes I made to fix your problem were :
  1. The form itself was saved with a value in the .Filter property. This was removed.
  2. The control [ChartNum] was updated to change properties :
    1. .EnterKeyBehavior set from "New Line in Field" to "Default". This was ensuring the default control on the form was not being triggered as it would otherwise have been.
    2. .ScrollBars set from "Vertical" to "None". This just looked wrong.

It seemed to work fine after I'd made those changes. I assume it's what you're after.
Feb 25 '11 #17
sueb
379 256MB
You're right, NeoPa, I posted in the wrong thread--sorry!

Also, these changes did correct the behaviors I was asking about, but I'm going to ask something further (and I apologize for the length of this post--tell me if I should actually put this in another thread).
Feb 28 '11 #18
NeoPa
32,556 Expert Mod 16PB
There are a few issues with this Sue. Let me explain :
  1. As you say, it should be in its own, separate, thread. I will do that for you.
  2. The database has a reference to a Novell library for picking dates. This is not generally available and I don't have a copy, so I can't even run your database now, as things stand. I would need you to attach the file C:\Novell\GroupWise\gwdpk.ocx. It would probably need to be zipped to be attachable.
  3. The scope of the question is too broad. It rather asks me to do the design and implementation for your project. I'd like to be able to help, but I'd need to do it in a more focused way. I could possibly post concepts that you would need to include in your database. Otherwise, it's just too much of an ask.

Looking again at the new question (which can now be found at Add Items Not In List), I may be able to post something. I'll see what I can do anyway, and we can take it from there.
Mar 1 '11 #19
sueb
379 256MB
Thanks for all this, NeoPa--I'll move to the new thread for the rest of the discussion, but here's the library reference for you. (I actually had an idea last night about simplifying this--I'll try it out and post what I find out in the new thread.)
Attached Files
File Type: zip GWDPK.zip (15.7 KB, 105 views)
Mar 1 '11 #20
NeoPa
32,556 Expert Mod 16PB
Sweet. I imported into the same folder as the database and it recognised it without my having to fix anything :-)
Mar 1 '11 #21
sueb
379 256MB
Great! It's so rare for something to just slip into place, isn't it?
Mar 1 '11 #22

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

Similar topics

4
by: Daniele petracca | last post by:
<SCRIPT TYPE="text/javascript"> if (screen.width==1024) { distanza=100; sinistra=100; } else { distanza=10; sinistra=10; } document.write(screen.width);
0
by: raza | last post by:
I am trying to create a new mdb in C# using ADOX, i am able to create DB , i want to add a username/password on that db , i have tried so many things , cant make it to work , please help ...
0
by: Earl Teigrob | last post by:
I am having a problem where the bitmap image that I just created and saved to disk can not be found but the code in another area of the program. When I reattempt to access the same image, it...
4
by: mcwooq | last post by:
Hi, I just installed the VS.Studio 2005 Team Edition for Developper and encountered severe problems with debugging ASP.NET 2.0 projects. Even newly empty created ASP 2.0 projects can't debug...
17
by: stubbsie | last post by:
Hi, I have redesigned our official public government website in .net and it has taken me a few months to redo. I have been the sole designer of the website from its humble beginnning a few years...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
15
by: A. Farber | last post by:
Hello, I'm programming a web game on OpenBSD, but am also trying to keep in runnable on Linux and Cygwin. I have a list of tables at which a player/kibitzer can sit down or create a new empty...
0
by: Chris B | last post by:
Howdy, When the AddNew button is clicked on the BindingNavigator, a new row is made in the datagrid and the row selector moves to that newly created row, what is the method that moves the selector...
22
by: DL | last post by:
Hi, What I wanted to do is to call a function from a newly created element. But it stumbled me. Here's the line that references the newly created element and I used the alert function for...
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
1
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.