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

ADO new record #Error why??

Hello Everyone

I have a main form (frmNewOrder) and a sub form (SubOrderBeneficiary).
On the main form I have a button which sends the Subform
(SubOrderBeneficiary) to a newrecord. Everything works fine expect that
when I press the button, the controls on the subform display an #Error
for a fraction of a second when changing from the current record on the
subform to the new record and theneverything works fine.

Does anyone knows how can I prevent this as it does not look
professional?

The code Im using is as follows:

Private Sub cmdNewBene_Click()
On Error GoTo Err_cmdNewBene_Click

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set SubBen = Me.SubOrderBeneficiary.Form

With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With

Set SubBen.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Me.SubOrderBeneficiary.SetFocus

Exit_cmdNewBene_Click:
Exit Sub

Err_cmdNewBene_Click:
MsgBox "Your request could not be processed. Err 14 - " &
Err.Description & Err.Number, vbCritical, "Error"
Resume Exit_cmdNewBene_Click
End Sub
Any comments and possible solution would help me a lot.

Thanks in advanced.
GAVO.

Dec 1 '05 #1
20 2237
GAVO-UK wrote:
Hello Everyone

I have a main form (frmNewOrder) and a sub form (SubOrderBeneficiary).
On the main form I have a button which sends the Subform
(SubOrderBeneficiary) to a newrecord. Everything works fine expect that
when I press the button, the controls on the subform display an #Error
for a fraction of a second when changing from the current record on the
subform to the new record and theneverything works fine.

Does anyone knows how can I prevent this as it does not look
professional?

The code Im using is as follows:

Private Sub cmdNewBene_Click()
On Error GoTo Err_cmdNewBene_Click

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set SubBen = Me.SubOrderBeneficiary.Form

With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With

Set SubBen.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Me.SubOrderBeneficiary.SetFocus

Exit_cmdNewBene_Click:
Exit Sub

Err_cmdNewBene_Click:
MsgBox "Your request could not be processed. Err 14 - " &
Err.Description & Err.Number, vbCritical, "Error"
Resume Exit_cmdNewBene_Click
End Sub
Any comments and possible solution would help me a lot.

Thanks in advanced.
GAVO.


Can you do something like this? Create a button in the main form with
code similar to
Me.SubFormName.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec
Dec 1 '05 #2
Your code does send the subform to a new record and does not display
the #Error, but it does not allow me to EDIT the new record.

Any other possible solutions?

Thanks
GAVO.

Dec 1 '05 #3
GAVO-UK wrote:
Your code does send the subform to a new record and does not display
the #Error, but it does not allow me to EDIT the new record.

Any other possible solutions?

Thanks
GAVO.

Do you have AllowEdits set to true? Is your recordsource for the form
updateable?
Dec 1 '05 #4
My Form is unbound and yes i can edit records?? what about my code,
would you think of anything that I could do to prevent the #Error?

Thanks

Dec 1 '05 #5
GAVO-UK wrote:
My Form is unbound and yes i can edit records?? what about my code,
would you think of anything that I could do to prevent the #Error?

Thanks

Haven't a clue. Maybe set Painting or Repainting to False until the
code executes. Maybe Application.Echo = False too.
Dec 1 '05 #6
GAVO-UK wrote:
Any comments and possible solution would help me a lot.


I'm glad you said that. My answer for almost all record selection,
creation and navigation problems on forms and subforms is this:

Access 2003 costs $130 CAD (Staples Business Depot 2005-11-30). It does
a few things superbly. One of these is to handle record selection,
creation and navigation on forms and subforms. Remove your code and
buttons and let Access do its job. That's what you paid the $130 CAD or
its equivalent for.

I've programmed Database User Interfaces for more than twenty years;
that's what I do.

Dec 1 '05 #7
Has anyone actually bought anything from you on this news group? I
really doubt it.

Still, any comments about my problem, highly appreciated.
GAVO.

Dec 1 '05 #8
You're welcome.

Dec 1 '05 #9
"GAVO-UK" <an****@peopleex.com> wrote
Has anyone actually bought anything from you on this news group? I
really doubt it.


I suggest you re-read Lyle's post. You obviously missed his point.

--
Darryl Kerkeslager

Dec 1 '05 #10
No, no one has actually bought anything from me on this news group.
So your doubt is well-justified.
Of course, I have nothing for sale, so this may not be so surprising.

Dec 1 '05 #11
GAVO-UK wrote:
Has anyone actually bought anything from you on this news group? I
really doubt it.


Many, many of us have benefitted from Lyle's posts here over the years.

Basically, what he's saying is you have written code needlessly and what
you describe in your post as what you're trying to do is already done by
Access. So you're struggling (needlessly) to code something that Access
already does for you.

Just make the recordsource of the sub form SubOrderBeneficiary:

SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
forms!frmNewOrder!SomeField

When you move from record to record in frmNewOrder, the display in
SubOrderBeneficiary will change.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Dec 2 '05 #12
rkc
GAVO-UK wrote:
Has anyone actually bought anything from you on this news group? I
really doubt it.


I've stolen a thing or two from him.
Dec 2 '05 #13
If my post offended anyone, Im sorry about that, its just that this
other day this guy offered my to pay him to solve my problem in this
news group and this other time some one else offered to sell me a pice
of code/App that did what i was looking for.

I read you post in hurry and missed the point completely.
Thanks anyway for you trying to help

GAVO

Dec 2 '05 #14
If my post offended anyone, Im sorry about that, its just that this
other day this guy offered my to pay him to solve my problem in this
news group and this other time some one else offered to sell me a pice
of code/App that did what i was looking for.
I read you post in hurry and missed the point completely.
Thanks anyway for you trying to help

-----------------------------

Tim

I know that Access does something like that, my problem is that the
subform which I'm talking about is not linked to the main form but to
another sub form, let me explain.

This is an ADP application with an SQL back end, which will be accessed
using the internet (ADSL or Dial Up). I am using unbound forms and
subforms and setting their recordset from code.

The main form (frmNewOrder - Unbound) has two subforms SubForm1
(subNewOrderCustomer - being the main subform) and SubForm2
(SubNewOrderBeneficary - Linked to Subform 1). What I'm trying to do
is; call a code using a button from the Main form which would send the
just the subform 2 to a new record and the SubForm 1 remain in its
current record.

Maybe I'm struggling in something which is done easily, but then as I
already said, my code is working its just that it display an #Error for
a fraction of a second in the controls of SubForm 2 before sending it
to a new record.

Jaime.

Dec 2 '05 #15
TC
Maybe try this:

1. Unbind all of the form controls from the datasource;
2. Do whatever it is that causes the controls to say #Error;
3. Rebind the controls.

This would only take a few lines of code & could work quite well IMO.

HTH,
TC

Dec 2 '05 #16
"TC" <aa**********@yahoo.com> wrote
1. Unbind all of the form controls from the datasource;
2. Do whatever it is that causes the controls to say #Error;
3. Rebind the controls.


Dim c As Boolean
c = (Me.RecordsetClone.RecordCount > 0)

Me!btnSortByName.Enabled = c
Me!btnSortByLevel.Enabled = c
If c Then
Me!txtName.ControlSource = "off_name"
Me!txtLevel.ControlSource = "cs_level"
Else
Me!txtName.ControlSource = vbNullString
Me!txtLevel.ControlSource = vbNullString
End If
--
Darryl Kerkeslager

Dec 2 '05 #17
TC
Um, sorta. I had more like this in mind:

' unbind the controls.
dim ctl as control
for each ctl in me.controls
with ctl
if .controlsource<>"" then
.tag = .controlsource
.controlsource=""
endif
end with
next
' now do the thing which causes #error to occur.
' ( do thing ... do thing )
' rebind the controls.
for each ctl in me.controls
with ctl
if .tag<>"" then
.contrtolsource = .tag
.tag=""
endif
end with
next

That code is a bit rough because it assumes that the tag properties are
blank to begin with, and that they are not already used for other
purposes. But it would be easy to store the controlsource values
somehow else, eg. in a collection.

HTH,
TC

Dec 2 '05 #18
TC.

I use a similar code to check for nulls, therefore my tags are already
in use. What other way can I implement you code and use an alternative
to tags, I know you mentioned a possible solution but ! have no idea
how to do it! any guidelines?

Thanks
GAVO

Dec 2 '05 #19
TC
Try this (untested):

dim cs as collection
set cs = new collection

' unbind the controls.
dim ctl as control
for each ctl in me.controls
with ctl
if .controlsource<>"" then
cs.add .name & "|" & .controlsource, .name ' item, key.
.controlsource=""
endif
end with
next

' now do the thing which causes #error to occur.
' ( do thing ... do thing )

' rebind the controls.
dim v as variant, n as integer
for each v in cs
n = instr(v, "|")
me.controls(left$(v,n-1)).controlsource = mid$(v, n+1)
next
set cs = nothing

HTH,
TC

Dec 2 '05 #20
"GAVO-UK" wrote
If my post offended anyone, Im sorry about that, its just that this
other day this guy offered my to pay him to solve my problem in this
news group and this other time some one else offered to sell me a pice
of code/App that did what i was looking for.


I'd wager that the "this guy" and the "some one else" to whom you refer are
the same person, someone who uses the newsgroup primarily to market his
services and a code CD with code from "unknown sources" and who refuses to
observe USENET rules and the newsgroup's charter's prohibition against
advertising. In recent years, only one "this guy" has done so, and it
definitely was not Lyle. You need to carefully differentiate between the one
person who offended you and the rest of us who are in the newsgroup to
assist others.

I have been around this newsgroup ever since it was created, and I've read a
lot of Lyle's posts. We have had our disagreements from time to time, but I
have NEVER, EVER seen him advertise in this newsgroup. I do not believe he
would violate that provision of the charter, even if his work was suitable
for "newsgroup marketing", which I think it is not.

Larry Linson
Microsoft Access MVP
Dec 2 '05 #21

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

Similar topics

6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
2
by: RC | last post by:
I am getting the following error message. "Write Conflict this record has been changed by another user since you started edting it. If you save the record, you will overwrite the changes...." I...
3
by: hebandgene | last post by:
When I delete a record in a subform I get the warning that I'm about to delete a record, followed by an error "No current record." When I click OK obviously the record is deleted and it goes to...
20
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
4
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete...
8
by: Tom | last post by:
Hi I have an aspx page which has javascript to configure xmldata. I added breakpoint to the button method. When I click submit button, it did not go to those breakpoint and show the following...
5
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
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?
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,...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.