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

Cannot save Form changes with VBA

I have a form that is used to ID and then load Excel files into Access.
I use labels on the form to record which file was last loaded. That was
accomplished with a simple lblFileLoaded = strFullFileName. The label
would show the file name and when the form was closed and then opened
it would still show the name of the last file loaded. That preserves an
important piece of information.

Suddenly the form has stopped doing that. When you close the form and
reopen it the lbl is blank or has the name from the second prior session.

At someone's suggestion I tried to Save the form on exit. with
"DoCmd.Save acForm, "frmLoad". It gives an error msg of
"the object "frmLoad" is not loaded. The form is loaded and the
following test routine, found on the web, confirms that it is loaded.

Sub test()
Dim IsOpen As Boolean
IsOpen = adhIsFormOpen("frmLoad")
Debug.Print IsOpen

End Sub
Public Function adhIsFormOpen(strname As String) As Boolean
On Error Resume Next
Dim FIsOpen As Boolean
FIsOpen = CurrentProject.AllForms(strname).IsLoaded
adhIsFormOpen = (Err.Number = 0) And FIsOpen
Err.Clear
End Function

Anyway I really need to have these labels saved on exit

Any ideas?

Thx
Kevin
May 31 '08 #1
2 4000
Labels are controls with static captions, such as: "Name" and "DOB".
Textboxes are often associated with labels and in them we can be enter
or modify data like "Larry Linson" and "1909-04-01". TextBoxes may
have default values.
If the form and textbox are bound to a field in a table then the
changes made to the textbox are likely to be saved in that field in
that table and to appear next time we open the Form and navigate to
the record.

But there is nothing inherent or implicit in a form which permits the
saving of data entered into a textbox. If we open the form in design
mode and change the caption of a label or the default value of a
textbox and save the form then the new caption or default value will
be saved with the form.

I think neither a bound form, nor changes in the form's design is what
you want to do.

This may effect what you want to do (for a control named "ExcelPath"):

Private Sub Form_Load()
On Error Resume Next
ExcelPath.Value = _
CurrentProject.AllForms(Me.Name).Properties("Defau ltExcelPath").Value
End Sub
Private Sub Form_Unload(Cancel As Integer)
With CurrentProject.AllForms(Me.Name).Properties
.Add "DefaultExcelPath", ExcelPath.Value
.Item("DefaultExcelPath").Value = ExcelPath.Value
End With
End Sub

Of course, there will be no default value saved until the second time
the form is opened.
On May 31, 8:45*am, "KC-Mass" <connearneyATcomcastDOTnetwrote:
I have a form that is used to ID and then load Excel files into Access.
I use labels on the form to record which file was last loaded. *That was
accomplished with a simple lblFileLoaded = strFullFileName. *The label
would show the file name and when the form was closed and then opened
it would still show the name of the last file loaded. That preserves an
important piece of information.

Suddenly the form has stopped doing that. *When you close the form and
reopen it the lbl is blank or has the name from the second prior session.

At someone's suggestion I tried to Save the form on exit. with
"DoCmd.Save acForm, "frmLoad". *It gives an error msg of
"the object "frmLoad" is not loaded. *The form is loaded and the
following test routine, found on the web, *confirms that it is loaded.

Sub test()
* Dim IsOpen As Boolean
* IsOpen = adhIsFormOpen("frmLoad")
* Debug.Print IsOpen

End Sub
Public Function adhIsFormOpen(strname As String) As Boolean
* * On Error Resume Next
* * Dim FIsOpen As Boolean
* * FIsOpen = CurrentProject.AllForms(strname).IsLoaded
* * adhIsFormOpen = (Err.Number = 0) And FIsOpen
* * Err.Clear
End Function

Anyway I really need to have these labels saved on exit

Any ideas?

Thx
Kevin
May 31 '08 #2
Thanks very much.

The form is unbound so I am not looking to fill text boxes with the data
as that would not preserve the data. I could certainly tie it all to a
table but
label.captions seemed an easy way to hold the few pieces of data.

I just now got the form to save using the reference me.name vice a literal,
"frmLoad". Got that style of reference from your code below.

Thanks again.
"lyle fairfield" <ly************@gmail.comwrote in message
news:8d**********************************@x35g2000 hsb.googlegroups.com...
Labels are controls with static captions, such as: "Name" and "DOB".
Textboxes are often associated with labels and in them we can be enter
or modify data like "Larry Linson" and "1909-04-01". TextBoxes may
have default values.
If the form and textbox are bound to a field in a table then the
changes made to the textbox are likely to be saved in that field in
that table and to appear next time we open the Form and navigate to
the record.

But there is nothing inherent or implicit in a form which permits the
saving of data entered into a textbox. If we open the form in design
mode and change the caption of a label or the default value of a
textbox and save the form then the new caption or default value will
be saved with the form.

I think neither a bound form, nor changes in the form's design is what
you want to do.

This may effect what you want to do (for a control named "ExcelPath"):

Private Sub Form_Load()
On Error Resume Next
ExcelPath.Value = _
CurrentProject.AllForms(Me.Name).Properties("Defau ltExcelPath").Value
End Sub
Private Sub Form_Unload(Cancel As Integer)
With CurrentProject.AllForms(Me.Name).Properties
.Add "DefaultExcelPath", ExcelPath.Value
.Item("DefaultExcelPath").Value = ExcelPath.Value
End With
End Sub

Of course, there will be no default value saved until the second time
the form is opened.
On May 31, 8:45 am, "KC-Mass" <connearneyATcomcastDOTnetwrote:
I have a form that is used to ID and then load Excel files into Access.
I use labels on the form to record which file was last loaded. That was
accomplished with a simple lblFileLoaded = strFullFileName. The label
would show the file name and when the form was closed and then opened
it would still show the name of the last file loaded. That preserves an
important piece of information.

Suddenly the form has stopped doing that. When you close the form and
reopen it the lbl is blank or has the name from the second prior session.

At someone's suggestion I tried to Save the form on exit. with
"DoCmd.Save acForm, "frmLoad". It gives an error msg of
"the object "frmLoad" is not loaded. The form is loaded and the
following test routine, found on the web, confirms that it is loaded.

Sub test()
Dim IsOpen As Boolean
IsOpen = adhIsFormOpen("frmLoad")
Debug.Print IsOpen

End Sub
Public Function adhIsFormOpen(strname As String) As Boolean
On Error Resume Next
Dim FIsOpen As Boolean
FIsOpen = CurrentProject.AllForms(strname).IsLoaded
adhIsFormOpen = (Err.Number = 0) And FIsOpen
Err.Clear
End Function

Anyway I really need to have these labels saved on exit

Any ideas?

Thx
Kevin

May 31 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christopher Brandsdal | last post by:
Hi! I get an error when I run my code Is there any other way to get te information from my form? Heres the error I get and the code beneath. Line 120 is market with ''''''''''''Line...
2
by: icedgar | last post by:
am using the following script in the BeforeUpdate area of a main form. Private Sub Form_BeforeUpdate(Cancel As Integer) Dim strMsg As String strMsg = "Do you wish to save your changes?" If...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
8
by: dbuchanan | last post by:
Hello, What does this error mean? "The event click is read-only and cannot be changed" This is a design-time error. It is displayed instead of the form. Here is the full text \\ "One or...
0
by: Patty05 | last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
6
by: subhashkumar | last post by:
Running data Append to a table Dear All, I need a help from this forum, I was developing a small tools for stock market. I get stuck when trying to save the running changes in a data field...
2
by: Matuag | last post by:
Hi All, I want to create following command buttons on a Form which users can edit. Save ( Save Changes made) Cancel ( Undo data changes) Exit ( Close form) I am using Macros for each of...
2
by: KC-Mass | last post by:
I have a form that is used to ID and then load Excel files into Access. I use labels on the form to record which file was last loaded. That was accomplished with a simple lblFileLoaded =...
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...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.