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

Subform displaying existing record won't display new record

63
I have a subform which is bound to a query which will display records using an ID# supplied from a listbox in the parent form.

That same subform is also used to create new records using the following code in a "New Record" commandbutton:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
Both functions work fine. However, if I have a selected record displayed, and I click the "New Record" button, it does not move to a new record. It just stays on the selected record and any edits I make affect that selected record.

Any help you can provide is appreciated!
Jan 21 '09 #1
21 7084
puppydogbuddy
1,923 Expert 1GB
If your button is executing from the main form, I believe you have to set focus on the subform to execute the new record command for the subform.
Try your code this way:
Expand|Select|Wrap|Line Numbers
  1. Me.YourSubformControlName.Form.SetFocus
  2. DoCmd.GoToRecord , , acNewRec
  3.  
Jan 22 '09 #2
postman
63
Thanks for the suggestion, puppydogbuddy. I tried it, but I get the following error:

Run-time error '2449': There is an invalid method in an expression.

It highlights the line with the "SetFocus" method for the form. I tried various approaches for the SetFocus, but they all end in the same error.

Any idea why?

Thanks for your help!
Jan 22 '09 #3
puppydogbuddy
1,923 Expert 1GB
oops, I forgot to set focus on a control on the subform source object(the form embedded in the subform control).

See this link: How to select controls on a subform with setFocus method in Access 2002
Expand|Select|Wrap|Line Numbers
  1. Me!YourSubformControlName.Form![ID].SetFocus 
  2. DoCmd.GoToRecord , , acNewRec 
  3.  
Jan 22 '09 #4
postman
63
Thanks for the info. It wasn't working, but after looking at the table, I found that new records were being created, but the bound fields in the subform weren't clearing to display the new record--they were still displaying the selected record.

Ideas?

Thanks!
Jan 22 '09 #5
puppydogbuddy
1,923 Expert 1GB
Is the subform's "allow additions" property set to "Yes"?
Jan 23 '09 #6
NeoPa
32,556 Expert Mod 16PB
@postman
Perhaps you need to requery the subform after the item has been added.
Jan 26 '09 #7
postman
63
I just realized what the problem probably is. The subform is bound to a query which uses a listbox value as the criteria. If a record is selected in the listbox, the subform is going to display those contents regardless of what's happening in the table.

I'll try a few things on that track and post the results...or more questions.
Jan 27 '09 #8
NeoPa
32,556 Expert Mod 16PB
That's about the size of it. The requery should help ;)
Jan 27 '09 #9
postman
63
The simplest fix to the problem was just changing the subform's "DataEntry" property to True when the "Create New Record" button is clicked, and to False when the "Display Records" button is clicked.

But that created the opposite problem, now:
If I go first to Display Records, it will display the selected records fine.
But if I first Create a new Record, then go to Display Records, the subform won't display the selected record from the listbox.

(The subform's recordsource is a query that uses the listbox value as criteria. The Listbox's click event does requery the subform.)

Not sure why this is happening.
Jan 27 '09 #10
ChipR
1,287 Expert 1GB
From DataEntry Property:
The Data Entry property doesn't determine whether records can be added; it only determines whether existing records are displayed.
Jan 27 '09 #11
NeoPa
32,556 Expert Mod 16PB
@postman
I suggest that your solution possibly wasn't one then.

I would try looking at the .Requery route.
Jan 27 '09 #12
postman
63
@NeoPa
The .Requery route did not work.

After further testing, it appears to be a focus issue. I tried the earlier suggestions for moving the focus and I can't get the focus to move to the subform.

I even made test buttons on the parent form with code to just move the focus to a control on the subform and it won't work. The focus stays with the parent form. Not sure why that won't work.
Jan 27 '09 #13
NeoPa
32,556 Expert Mod 16PB
@postman
Could we see the code you tried.
Jan 27 '09 #14
postman
63
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command173_Click()
  3.  
  4.      Form_AttDetail.aiDate.SetFocus
  5.  
  6. End Sub
  7.  
Command173 is the command button in the parent form.
Form_AttDetail is the subform object.
aiDate is a control in that subform.

Thanks.
Jan 28 '09 #15
puppydogbuddy
1,923 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command173_Click() 
  2.  
  3.      Me!Form_AttDetail.Form!aiDate.SetFocus 
  4.  
  5. End Sub
  6.  
Jan 28 '09 #16
postman
63
@puppydogbuddy

It gives an error stating it "can't find the field 'Form_AttDetail' referred to in your expression."

I tried changing it to
Expand|Select|Wrap|Line Numbers
  1. Me.attDetail.Form!aiDate.SetFocus
This eliminated the error, but nothing happens ("attDetail" is the subform control name and "AttDetail" is the subform name).
Jan 28 '09 #17
NeoPa
32,556 Expert Mod 16PB
Check out Referring to Items on a Sub-Form. I think it may explain the situation fully enough.

Let us know if you still have problems after reading through it.
Jan 28 '09 #18
puppydogbuddy
1,923 Expert 1GB
see the suggested syntax from the link I gave you in post #4
Expand|Select|Wrap|Line Numbers
  1. Me!attDetail.SetFocus
  2. Me!attDetail.Form!aiDate.SetFocus
  3.  
Jan 28 '09 #19
postman
63
@puppydogbuddy
Thanks. That did the trick.
The syntax I used was this:
Expand|Select|Wrap|Line Numbers
  1. Me.attDetail.SetFocus
  2. Form_AttDetail.aiDate.SetFocus
I use "Form_AttDetail" because it's shorter and the intellisense will display the controls/properties which means less typing. Using the the "!" method does not give the intellisense menus. Is there a disadvantage to this?

I still have to switch the recordsource of the subform to the table if I'm adding new records and to the query if I'm displaying records based on the listbox selection.

Thanks for all your help!
Jan 28 '09 #20
puppydogbuddy
1,923 Expert 1GB
Postman,
Glad to see you finally got the syntax to work.

In regards to the bang (!) vs dot (.) operators: Although they are now often interchangable .....there are technical differences between them that could more strictly enforced by the Access compiler in future editions of Access, prompting code changes for compliance.

Technically, the ! operator is used to indicate that what follows is a user-defined item (e.g.an element of a collection). For example, use the ! operator to refer to an open form, an open report, or a control on an open form or report.

On the other hand, the . (dot) operator usually indicates that what follows is an item defined by Microsoft Access. For example, use the . (dot) operator to refer to a property of a form, report, or control.

In regards to your statement about having the proper code for switching between existing records and new records, here is one way you can branch your code:

If Not Me.NewRecord then
-----XXXXX code for existing record
Else
------xxxxx code for new record
End If
Jan 28 '09 #21
postman
63
Thanks for the info. The lingo helped me do some research on the bang vs dot vs quotes thing.

I found a couple interesting articles...
http://my.advisor.com/articles.nsf/aid/05352

"In addition to ControlName being a member of the Controls collection of the form, it's also a property of the form...every time you add a control to a form (or report), Access adds a property with the same name and type as your control to the form's class in your VBA project...Using dots rather than bangs also makes your code run a bit faster."

http://blogs.msdn.com/frice/archive/.../18/75685.aspx

"Using dots rather than bangs also makes your code run a bit faster....[The bang operator] also has the disadvantage of causing a speed penalty. Why? ...Behind the scenes, Access translates the dot-and-bang reference to the parentheses and quotes style anyway. As a result, while the bang will save you a few strokes, the translation will incur a performance penalty. Thus the recommendation is to always use the parentheses and quotes styles when referring to a member of a collection "

Thanks again! :-)
Jan 30 '09 #22

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

Similar topics

0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
6
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
5
by: Thelma Lubkin | last post by:
I have a form/subform with the common one-to-many relationship. The form allows user to display records and move to other records via the selector, to add,delete, and edit them, with the related...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
10
by: sara | last post by:
Hi - I am developing a simple app, and just found a problem that I can't fix after 4 hours of trying. I display a list of customers, and the user chooses one and displays "orders". The...
14
kcdoell
by: kcdoell | last post by:
Hello: I have a form (Default view =single form) with a subform (Default view =continuous forms) embedded into it. In the form I have three controls that display the Division, Working Region &...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.