473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I capture Form Variables before editing them

101 New Member
I am using a form to show a list of Appointment records. I want to choose a record from the list and edit the fields. However. I wish to capture the record fields before editing as I need this information to subsequently delete the old Outlook appointment.

I have tried capturing this info using the before edit Event and have declared results as Public variables in a Module.

However, when I try to recall the Public variables they are showing empty.

Is this because the before edit Sub is within the same class module? or am I doing something stupid.
Oct 29 '11 #1

✓ answered by ADezii

  1. Date Variables can represent Dates in the Range of 1/1/100 to 12/31/999. There is no such Date as:
    Expand|Select|Wrap|Line Numbers
    1. 00/00/0000
  2. When dealing with Variables, especially Public Variables, their names are very important in identifying their Scope, Type, and Context.
    Expand|Select|Wrap|Line Numbers
    1. gdteOldDate
  3. When looking at the above Variable in Code, it is easily recognized as Public/Global(g), a Date Value(dte), representing an Old Date.
  4. You have 2 Options to eliminate the Syntax Error:
    1. Set the Value to 0 as indicated below:
      Expand|Select|Wrap|Line Numbers
      1. oldDate = 0
      will display as:
      Expand|Select|Wrap|Line Numbers
      1. 12:00:00 AM
    2. Declare oldDate as a Variant, and Reset to Null:
      Expand|Select|Wrap|Line Numbers
      1. Public gvarOldDate As Variant
      Expand|Select|Wrap|Line Numbers
      1. gvarOldDate = Null
      will return Null

12 2114
ADezii
8,834 Recognized Expert Expert
Let's assume that you wish to Capture the First Name, MI, and Last Name Values on a Form prior to Editing.
  1. Declare your Variables as Public in a Standard Code Module
    Expand|Select|Wrap|Line Numbers
    1. Public gstrFirstName As String
    2. Public gstrMI As String
    3. Public gstrLastName As String
    4.  
  2. In the Form's Current() Event, assign Values to those Variables (First and Last are required, MI is not):
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2. 'Must Initialize the Public Variables, avoid carryovers
    3. gstrFirstName = ""
    4. gstrMI = ""
    5. gstrLastName = ""
    6.  
    7.   With Me
    8.     gstrFirstName = ![First]
    9.     gstrMI = Nz(![MI])
    10.     gstrLastName = ![Last]
    11.   End With
    12. End Sub
  3. The Values in these Variables will persist until you Navigate to another Record, and will be accessible for the lifetime of your Application. Should you Edit any one or more of these Fields, the Variables will still retain their Original Values.
Oct 29 '11 #2
NeoPa
32,556 Recognized Expert Moderator MVP
This would be so much easier if you showed the code you're using and explained what happened when it failed. I think I can guess, but I may be wrong - and I don't see why we have to keep guessing when a bit more care and preparation would make a full question.

I suspect you public variables have been declared in a class or object (Form or Report) module. Such modules can declare public variables, but when they are accessed from outside of that same module, they need to be referenced explicitly. Assuming the variable is declared as public in the module for a form named "frmMain", and the variable itself is named strName, then the full reference to them would be Form_frmMain.strName. As you know from an earlier thread, this cannot be referenced from SQL. No public variables can.

PS. For a variable to be referenced anywhere in your code without the module specifier, it needs to be declared in a Standard Module.
Oct 29 '11 #3
Cyd44
101 New Member
Hi Adezii

Thanks for this. I have placed your code but I am using 2 date fields and not sure how to intitialise these and am getter an error on the oldDate field.

My Code is
Expand|Select|Wrap|Line Numbers
  1. Dim oldLocation As String
  2. Dim oldStart As Date
  3. Dim oldDate As Date
  4. Dim oldName As String
  5.  
  6. oldLocation = ""
  7. oldStart = #12:00:00 AM#
  8. oldDate = #00/00/0000#
  9. oldName = ""
  10.  
  11.   With Me
  12.     oldLocation = ![BookLocation]
  13.     oldStart = Nz(![BookTime])
  14.     oldDate = ![BookStartDate]
  15.     oldName = ![BookName]
  16.   End With 
The oldStart is Date/Time (medium time) and oldDate in Date/Time (short date) These coorespond to the tble fields for BookTime & BookStartDate

I have declared the oldXXXX variables in a module as follows:-
Expand|Select|Wrap|Line Numbers
  1. Public oldLocation As String
  2. Public oldDate As Date
  3. Public oldStart As Date
  4. Public oldName As String
  5.  
When I run I get a Syntax error on the oldDate?
Oct 29 '11 #4
Cyd44
101 New Member
Hi NeoPa

I seem to be always falling foul of you. I can only assure you I am trying but as a novice I find it difficult to distinguish between being verbose and being brief. I was simply asking a question about capturing a form variable before editing it and did not give any further details in case I was being stupid. ADezii appears to have understood completely.

In relation to Module I am using, I was using Standard Code Module. I am hopefull that once I have resolved the Syntax error on initialising the variables (as per ADezii's code) my pain will go away.
Your comments, advice & assistance are always greatly appreciated but I do not always know how to put my question properly due to my lack of knowledge on Access and VBA syntax etc.
Oct 29 '11 #5
ADezii
8,834 Recognized Expert Expert
  1. Date Variables can represent Dates in the Range of 1/1/100 to 12/31/999. There is no such Date as:
    Expand|Select|Wrap|Line Numbers
    1. 00/00/0000
  2. When dealing with Variables, especially Public Variables, their names are very important in identifying their Scope, Type, and Context.
    Expand|Select|Wrap|Line Numbers
    1. gdteOldDate
  3. When looking at the above Variable in Code, it is easily recognized as Public/Global(g), a Date Value(dte), representing an Old Date.
  4. You have 2 Options to eliminate the Syntax Error:
    1. Set the Value to 0 as indicated below:
      Expand|Select|Wrap|Line Numbers
      1. oldDate = 0
      will display as:
      Expand|Select|Wrap|Line Numbers
      1. 12:00:00 AM
    2. Declare oldDate as a Variant, and Reset to Null:
      Expand|Select|Wrap|Line Numbers
      1. Public gvarOldDate As Variant
      Expand|Select|Wrap|Line Numbers
      1. gvarOldDate = Null
      will return Null
Oct 29 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
It seems your ability to express yourself isn't so bad Cyd. That post #5 was well said. I should appreciate that preparing such questions properly isn't so easy for most people, but I'm confident you'll get there with increasing experience. The improvement already is noticeable. I will try to bear that all in mind for future questions.

Anyway, for this question, that I'm still largely unclear about (notwithstanding ADezii's apparent comprehension), I would just comment that Date variables, unlike form controls and most fields, cannot contain Null values (which would typically be used to indicate a non-value). ADezii has already explained that the range of values doesn't allow all 0s, so if you must reflect that then you may be better advised to use a Variant variable to store your date value.
Oct 29 '11 #7
Cyd44
101 New Member
Thanks to Adezii I have changed the variable names to reflect that they are golbal and have add a prefix as either gdte or gstr.

Initilaly whilst I got no syntax error I was still not getting the correct results. I then realised why! I had set on entry event for each field to validate the owner. This was conflicting with the on Current() event for the Form (I think). I have since taken the en entrty() events out and the sub works OK.

Many thanks to Adezii I will set as best answer. Many thanks to NeoPa for the advice and gudance,
Oct 29 '11 #8
ADezii
8,834 Recognized Expert Expert
One last thought is that you must be very careful with Public/Global Variables due to their retention (Scope). This is why they must be Re-Initialized in the Current() Event for every Record or their Value(s) will persist to the Next/Previous Record.
Oct 29 '11 #9
Cyd44
101 New Member
Thanks ADezii

I will look at this and see. If we are initialising at the start of each loop, will it not set the golbals to null if we choose another record ......or not?
Oct 29 '11 #10
Cyd44
101 New Member
ADezii

I have tested the Global Variables and made a number of changes without closing and re-entering the form. It changed the globals to reflect the pre-edit details of the records chosen OK.

Think I am happy the variables are re-initialised each time.

Thanks for the advice anyway. Cheers mate
Oct 29 '11 #11
ADezii
8,834 Recognized Expert Expert
They have to be re-initialized for each Record. Suppose you are on the 1st Record, and 3 Public variables for First, MI, and Last get initialized to:
Expand|Select|Wrap|Line Numbers
  1. William 
  2. C
  3. Clanton
if you now Navigate to Record 2, and the Name is:
Expand|Select|Wrap|Line Numbers
  1. Thomas
  2.  
  3. Jefferson
When you retrieve the Values of the Variables they will read:
Expand|Select|Wrap|Line Numbers
  1. Thomas
  2. C
  3. Jefferson
because the Variable set to MI still maintains its prior Value. Makes sense?
Oct 29 '11 #12
Cyd44
101 New Member
I think I understand and it does appear logical that where a catured variable is Null it would retain the old value. Thankfully however, within my database, I will not have Null values in any of the variables that I wish to capture as these are the key fields to the string.

Think we can close this ADezii, dont you. I have marked your last as best answer and am happy with the help unless you feel that there may be some flaw in the logic.

Many thanks yet again
Oct 30 '11 #13

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

Similar topics

2
by: CCP | last post by:
I've got a simple HTML page containing a form and a few hidden variables. This form post into a .Net application (that lives in a seperate directory). The first thing I do in my codebehind is...
4
by: Philippe | last post by:
hi everybody, I let the user enter values in a Child Form. How can I post those values back to the MDIParent Form (which uses these values) ? By the way, is it possible to access Public...
1
by: ___Newbie___ | last post by:
Hello, What is the best way to implement a form based editing? The user would select first from a list control (highlighted selection) ? e.g. through a listbox or datagrid. Then, select from...
3
by: Marcel Balcarek | last post by:
Can I keep the value of (some of) my server variables across posts? I can define hidden form fields, but is there a better way? I have passed some form variables from one page to another and...
2
by: Wee Bubba | last post by:
my page is split into 2 frames. my upper frame contains a data entry form consisting of asp.net textbox server controls. my lower frame displays rows of data. when a user clicks the submit...
3
by: jethro_uk | last post by:
Hi there, I have a bizarre problem with FORM variables in ASP. Scenario using VI6, IE6, Windows2000 server: MyPage.ASP: .. .. ..
3
by: Jon | last post by:
Hello all, In my app, I'm opening up another window and doing a redirect to another app. Within this app, I need to do a Request.Form in order to retrieve a variable from app1. Can this be...
18
by: Thomas Lunsford | last post by:
I have inherited a set of asp pages that I now need to augment. In order to minimize changes to production code, I would like to make a "call" to an asp page from a new asp page. Existing code is...
1
by: madhavarao | last post by:
capture form to save into JPEG format in windows application uisng C#.net. But i want to save full form instead of active window. Thanks in advance
9
by: jmartmem | last post by:
Greetings, Perhaps someone can help me resolve what I hope is a simple dilemma... I have one ASP page (TEST_RoadmapData_Search.asp) which contains two list/menus within a form, which, upon...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
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
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...
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?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.