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

Textbox Data Transfer not updating when control is active

I am trying to automatically transfer data from one textbox to another between subforms within a 'main' form. I put this code into the Gotfocus eventprocedure:

Private Sub Date_GotFocus()
If Len(Trim$(Me![Date Fish].Value & "")) = 0 Then
'This checks for blank or space-filled date field - it will only transfer data if it has not already been entered.

Me![Date Fish] = [Forms]![Main Field Data Collection Form]![Field Data Collections Subform].[Form]![Water].[Form]![Date]

SendKeys "{F2}"
SendKeys "{TAB}"
SendKeys "+{TAB}"
End If
End Sub

It works - to an extent. The Sendkeys parts are trying to get the data to show up. It only shows up when I move to another control or subform.

But this is not how I want this to work - and maybe I am not doing this correctly at all.

I enter a date in one subform ("Water" - where data is always collected for that record)

Then I move to another subform ("Fish" where data is only entered for some records). Most often the Date will be the same - but not always. So when I move into the date textbox, I want the date from "Water" to move into the box. Then if it is different, I can edit it, otherwise it is 'defaulted' to the 'Water' date.

Is there a way to do this? I tryed defining the default value, but did not have success - perhaps I did not do it correctly.

The real problem is having the date entered only if data is entered in that subform. If no data is entered, then the date should not be entered either - That means I can not simply populate all the subform dates upon 'Loosing focus' in the 'Water' date subform either.

Hmmmm?
Nov 28 '06 #1
17 2561
MMcCarthy
14,534 Expert Mod 8TB
You should put this in the Before Update event and your syntax for finding the date on the subform is wrong.

If [Date Fish] is not a Date/Time data type it should be. Then you only have to check for null value.

I would also suggest you change the name of the field in Water subform from Date to something else as Date is a function in Access.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Date_BeforeUpdate()
  3.  
  4.    If IsNull(Me.[Date Fish]) Then
  5.       Me.[Date Fish] = [Forms]![Main Field Data Collection Form]![Field Data Collections Subform].Form![Water].Form![Date]
  6.    End If
  7.  
  8. End Sub
  9.  
Nov 28 '06 #2
NeoPa
32,556 Expert Mod 16PB
Do we want ...Form![Water].Form![Date]?
I would have thought ...Form![Water].[Date]
would be the correct format?
(See I'm learning new stuff all the time - a week ago I wouldn't have had a clue even to ask the question)
Nov 28 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Do we want ...Form![Water].Form![Date]?
I would have thought ...Form![Water].[Date]
would be the correct format?
(See I'm learning new stuff all the time - a week ago I wouldn't have had a clue even to ask the question)
We have a subform on a subform with a control. Each subform needs the .Form

Mary
Nov 28 '06 #4
NeoPa
32,556 Expert Mod 16PB
We have a subform on a subform with a control. Each subform needs the .Form

Mary
In that case would I be right in thinking the .[Water]. part refers to the second level subform object?
In which case we want :
[Forms]![Main Field Data Collection Form].[Field Data Collections Subform].Form.[Water].Form.[Date]
but (!)s can be used in most cases to replace the (.)s if unsure.
Nov 28 '06 #5
NeoPa
32,556 Expert Mod 16PB
Before you answer that one Mary.
I reread the original post and it looks like two sibling subforms rather than a grandfather - father - son relationship.
Are you sure it SHOULD be referenced as it has?
Nov 28 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Before you answer that one Mary.
I reread the original post and it looks like two sibling subforms rather than a grandfather - father - son relationship.
Are you sure it SHOULD be referenced as it has?

I based the code on the original code which indicated that there was a subform Water with a control called [Date] which was on a subform called 'Field Data Collections Subform' which was on a main form called 'Main Field Data Collection Form'.

If this is not the case then the code is wrong.

Just have to wait to find out.

Mary
Nov 29 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
I based the code on the original code which indicated that there was a subform Water with a control called [Date] which was on a subform called 'Field Data Collections Subform' which was on a main form called 'Main Field Data Collection Form'.

If this is not the case then the code is wrong.

Just have to wait to find out.

Mary
BTW, in this case it doesn't matter that Fish is a subform as long as the reference is on that form.
Nov 29 '06 #8
First Thanks much for everything. I changed the Textbox names from date to 'water date' and 'fish date'.

Mary - the code you offered does not work in the Beforeupdate eventproceure area. Nothing happens when put in the Beforeupdate eventprocedure.

The null check is not the problem, This is better than the one I had (I got is from another post here - and seemed sort of unnessesary as date formats won't allow spaces!)

But the Before update event is not registering. Don't know why. Must be a Form Flow Problem.

Maybe this explanation of the forms will help?....

Yes, it's a rather complicated form - but once working it is actually easy to use. The Water form and the Fish Form are 'Sister' forms - on the 'Field Data Collections' Form, which itself is a child form of the 'Main Field Data Collections Form). It allows a data collection of fish and water quality data for a site (field data collection) for numberous years (Main Field Data Collection).

But the dates for each are actually part of the Table that is 'Mother' of both Water and Fish, that is they are on the Field Data Collections Table - there is a 'Water Date' and a 'Fish Date' field on that table. They are entered on the subforms since that is where one enters the water and fish data. The Parent form is for other physical data - so you don't have to jump around a lot on the form.

Maybe this will help?
Nov 29 '06 #9
NeoPa
32,556 Expert Mod 16PB
No prizes for guessing your gender then ;).
I should just point out that I was not being sexist when I referred to the term 'grandfather - father - son', it's a common term that's been in use to describe this situation for a long time. Your terms are, of course, quite acceptable and intelligible too :).
Nov 29 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
First Thanks much for everything. I changed the Textbox names from date to 'water date' and 'fish date'.

Mary - the code you offered does not work in the Beforeupdate eventproceure area. Nothing happens when put in the Beforeupdate eventprocedure.

The null check is not the problem, This is better than the one I had (I got is from another post here - and seemed sort of unnessesary as date formats won't allow spaces!)

But the Before update event is not registering. Don't know why. Must be a Form Flow Problem.

Maybe this explanation of the forms will help?....

Yes, it's a rather complicated form - but once working it is actually easy to use. The Water form and the Fish Form are 'Sister' forms - on the 'Field Data Collections' Form, which itself is a child form of the 'Main Field Data Collections Form). It allows a data collection of fish and water quality data for a site (field data collection) for numberous years (Main Field Data Collection).

But the dates for each are actually part of the Table that is 'Mother' of both Water and Fish, that is they are on the Field Data Collections Table - there is a 'Water Date' and a 'Fish Date' field on that table. They are entered on the subforms since that is where one enters the water and fish data. The Parent form is for other physical data - so you don't have to jump around a lot on the form.

Maybe this will help?
At what stage do you want this event 'triggered'?

After the date is entered in the Water Subform or when user clicks into Fish subform or when the main form is opened or record changes?

Knowing when you want to trigger the event will determine where the code goes.

Mary
Nov 29 '06 #11
So I put the new blank test - for a null value in the data into the gotfocus event procedure and it works - but again like it did before. You move into the 'fish date' text box control, and nothing is there. Once you move away, up pops the date from 'water date'.

I want the date to show up when I move into the textbox, then allow editing if necessary - or simply tab to the lower subform where you enter data for fish.

Could if be the complicated way these forms are referenced and linked. The Fish subform is actually 2 forms (in a Tab) - The main one has the date on it - and is linked to the main form via a query. This was perhaps my most difficult thing to understand. I am still not sure I DO understand it - but it works. Its a query that's first field is:

Field Data Collections.*

The second field is 'Keynumber' - the number that links the field data collections with the sub tables/forms.

It has a criteria of:
[Forms]![Main Field Data Collection Form]![Field Data Collections Subform].[Form]![Keynumber]

Here is the SQL code:
Expand|Select|Wrap|Line Numbers
  1. ... SELECT DISTINCTROW [Field Data Collections].*, [Field Data Collections].Keynumber
  2. FROM [Field Data Collections]
  3. WHERE ((([Field Data Collections].Keynumber)=[Forms]![Main Field Data Collection Form]![Field Data Collections Subform].[Form]![Keynumber]));
  4.  
Each subform uses this Query as its Form Record Source.

Then each subform is linked to it's respective table (Fish to the Fish table), and linked child and master by 'keyvalue'.

The sub subforms - under the 'date' form is also linked by the keyvalues.

It works really well and looks very nice!
Nov 29 '06 #12
Mary -

I thought I had said the problem was with the 'when' of the the event already. But I guess I did not make that clear. I can get it to work - but it's when that is the problem.

There are really a couple points when it could be triggered - the main thing to maintain is that the date should remain blank - unless data is entered in the subform. So - if there is no fish data, then no date is entered.

So - practically, the date could be transfered into the control - that is the event made to work - ideally when the 'Fish Date' text box control is entered - or when data is entered in the Fish Data subform. Perhaps it should occur upon either event to give the user most flexiblilty.

Now another possibility I've thought of, but messy, is to populate the 'Fish Date' text box control immediately upon clicking on the subform Tab(I think I've been able to do this), then deleting the data if no Fish Data is entered. It would work, but there is always the possibility that quick or unusal navigation through the forms could result in messy data.
Nov 29 '06 #13
Could there be something like Me.Refresh? An update command? Using the .value property of the Control? That I could use in the evenprocedure of the 'Fish Date' Textbox control - or in an eventprocedure of the form, subform, etc.?
Nov 29 '06 #14
MMcCarthy
14,534 Expert Mod 8TB
Have you tried putting ...

Expand|Select|Wrap|Line Numbers
  1. =[Forms]![Main Field Data Collection Form]![Field Data Collections Subform].Form![Water].Form![Date]
  2.  
into the default value.

BTW, Don't put square brackets around the .Form commands as they are not fields.

Mary
Nov 29 '06 #15
me.refresh !

That was it! Now when I click on the 'Fish Date' control, it puts in the date from 'Water Date' and it shows up instantly without having to leave the control. That way if it is correct I simply tab or click to the next data entry point, or I edit the date to the correct one! Perfect. Now I have to add that to several other forms as well. Thanks!

Who knows why it was not refreshing (Updating was the wrong syntax for the action I desired)

What did I do? - I added the me.refresh command to the GotFocus eventprocedure, resulting in:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Fish_Date_GotFocus()
  2.  If IsNull(Me.[Date Fish]) Then
  3. 'This checks for blank or space-filled date field - it will only transfer data if it has not already been entered.
  4.     Me![Date Fish] = [Forms]![Main Field Data Collection Form]![Field Data Collections Subform].[Form]![Water].[Form]![Water Date]
  5.     Me.Refresh
  6. End If
  7. End Sub
  8.  
I woke up with this idea and did a Web search - just goes to show what 'sleeping on it' can accomplish with a problem. My other ideas concerned ways to refer directly to the Query that the subform was based on..... But I had no idea if that line of thought would have led to anything useful either!
Nov 29 '06 #16
MMcCarthy
14,534 Expert Mod 8TB
I'm glad its working for you.



me.refresh !

That was it! Now when I click on the 'Fish Date' control, it puts in the date from 'Water Date' and it shows up instantly without having to leave the control. That way if it is correct I simply tab or click to the next data entry point, or I edit the date to the correct one! Perfect. Now I have to add that to several other forms as well. Thanks!

Who knows why it was not refreshing (Updating was the wrong syntax for the action I desired)

What did I do? - I added the me.refresh command to the GotFocus eventprocedure, resulting in:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Fish_Date_GotFocus()
  2. If IsNull(Me.[Date Fish]) Then
  3. 'This checks for blank or space-filled date field - it will only transfer data if it has not already been entered.
  4. Me![Date Fish] = [Forms]![Main Field Data Collection Form]![Field Data Collections Subform].[Form]![Water].[Form]![Water Date]
  5. Me.Refresh
  6. End If
  7. End Sub
  8.  
I woke up with this idea and did a Web search - just goes to show what 'sleeping on it' can accomplish with a problem. My other ideas concerned ways to refer directly to the Query that the subform was based on..... But I had no idea if that line of thought would have led to anything useful either!
Nov 29 '06 #17
NeoPa
32,556 Expert Mod 16PB
Me.Refresh is good, but if there is any chance that data is updated elsewhere (someone else running the same database for instance) the Me.ReQuery may suit you better.
Refresh will show changes to individual records, but will not reflect additions or deletions done elsewhere.
Nov 29 '06 #18

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

Similar topics

2
by: Edward Mitchell | last post by:
I have Web Form (.aspx file) with a fair number of textboxes (<asp:textbox .... />) that I need to fill from a database and then save back to the database when I'm done. This presumably must be a...
1
by: sekisho | last post by:
I'm dynamically adding a column of labels and a column of text boxes to a panel on a webform, based on data returned from an SQL query, which the user builds by selecting options from a few...
2
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the...
1
by: Zyrthofar | last post by:
Hi I have three textboxes indicating the individual RGB values of a color. When the user leaves a textbox (Leave event), I check the validity of that number and saves the three values to a set of...
22
by: Tim | last post by:
Hi A while ago I got some help in writing a mock console. The idea was to write a VB app that contained a textbox, then run a process from within the app and redirect the stdout to the textbox. ...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
9
by: Phill W. | last post by:
VB.Net 2005 SP1 Windows Forms Application What's the fastest way to append text to a TextBox? I have an application that monitors data written to text files. It needs to scan some fairly...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.