dbTalk Databases Forums  

Opening a form to a specific record leads to #error for one field

comp.databases.ms-access comp.databases.ms-access


Discuss Opening a form to a specific record leads to #error for one field in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
buckskin
 
Posts: n/a

Default Opening a form to a specific record leads to #error for one field - 03-31-2011 , 07:45 PM






I'm opening a form like so;

strWhere = "[id] = " & lngRpt
DoCmd.openform "frmCC_Choice", , , , , acDialog, "usercodes"


The form opens and I run this form in the open event

'Dao code courtesy of Allen Browne in 2006

Dim rs As DAO.Recordset
With Forms!frmCC_Choice
Set rs = .RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs WHERE (((report_defs.Type) =" &
"'C'" & ")) ORDER BY report_defs.DateModified DESC;"

This all works - nearly. I can open the form at the record I require and
can then navigate the other records.
But the textbox bound to DateModified now shows #Error.

If I remove that sorting field from the recordsource then it displays ok.
It's obviously the sorting that screws things up (but I need it sorted).

Is there a quick fix?

Reply With Quote
  #2  
Old   
buckskin
 
Posts: n/a

Default Re: Opening a form to a specific record leads to #error for one field - 03-31-2011 , 08:13 PM






"buckskin" <buckskin (AT) mailinator (DOT) com> wrote

Quote:
This all works - nearly. I can open the form at the record I require and
can then navigate the other records.
But the textbox bound to DateModified now shows #Error.

If I remove that sorting field from the recordsource then it displays ok.
It's obviously the sorting that screws things up (but I need it sorted).

Is there a quick fix?


Just realised that in my current position, the code is NOT actually opening
the desired record (it goes to the first one). If I remove the sorting
field, everything does work but it's sorting on the PK instead of the date.

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Opening a form to a specific record leads to #error for one field - 03-31-2011 , 08:47 PM



buckskin wrote:

Quote:
I'm opening a form like so;

strWhere = "[id] = " & lngRpt
DoCmd.openform "frmCC_Choice", , , , , acDialog, "usercodes"


The form opens and I run this form in the open event

'Dao code courtesy of Allen Browne in 2006

Dim rs As DAO.Recordset
With Forms!frmCC_Choice
Set rs = .RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs WHERE (((report_defs.Type) =" &
"'C'" & ")) ORDER BY report_defs.DateModified DESC;"

This all works - nearly. I can open the form at the record I require and
can then navigate the other records.
But the textbox bound to DateModified now shows #Error.

If I remove that sorting field from the recordsource then it displays ok.
It's obviously the sorting that screws things up (but I need it sorted).

Is there a quick fix?


Your statement
Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs

Why do you select Type and DateModified again. They should already be
selected in report_defs.*.

Why are you setting the bookmark prior to code for finding the record?

Reply With Quote
  #4  
Old   
buckskin
 
Posts: n/a

Default Re: Opening a form to a specific record leads to #error for one field - 03-31-2011 , 11:19 PM



"Salad" <salad (AT) oilandvinegar (DOT) com> wrote

Quote:
buckskin wrote:

I'm opening a form like so;

strWhere = "[id] = " & lngRpt
DoCmd.openform "frmCC_Choice", , , , , acDialog, "usercodes"


The form opens and I run this form in the open event

'Dao code courtesy of Allen Browne in 2006

Dim rs As DAO.Recordset
With Forms!frmCC_Choice
Set rs = .RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs WHERE (((report_defs.Type) ="
&
"'C'" & ")) ORDER BY report_defs.DateModified DESC;"

This all works - nearly. I can open the form at the record I require
and
can then navigate the other records.
But the textbox bound to DateModified now shows #Error.

If I remove that sorting field from the recordsource then it displays
ok.
It's obviously the sorting that screws things up (but I need it sorted).

Is there a quick fix?


Your statement
Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs

Why do you select Type and DateModified again. They should already be
selected in report_defs.*.
Ah good point.

Quote:
Why are you setting the bookmark prior to code for finding the record?
Hmmm, the perils of copy/pasting code without understanding what it is. OK
so I should set the recordsource first then set the bookmark?
Quote:


Reply With Quote
  #5  
Old   
buckskin
 
Posts: n/a

Default Re: Opening a form to a specific record leads to #error for one field - 04-01-2011 , 04:25 AM



"Salad" <salad (AT) oilandvinegar (DOT) com> wrote

Quote:

Your statement
Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs

Why do you select Type and DateModified again. They should already be
selected in report_defs.*.

Why are you setting the bookmark prior to code for finding the record?
BTW thanks Salad it all works spiffingly well now!

Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Opening a form to a specific record leads to #error for one field - 04-01-2011 , 07:52 AM



buckskin wrote:

Quote:
"Salad" <salad (AT) oilandvinegar (DOT) com> wrote in message
news:kZqdnSwP97MBswjQnZ2dnUVZ_gidnZ2d (AT) earthlink (DOT) com...

buckskin wrote:


I'm opening a form like so;

strWhere = "[id] = " & lngRpt
DoCmd.openform "frmCC_Choice", , , , , acDialog, "usercodes"


The form opens and I run this form in the open event

'Dao code courtesy of Allen Browne in 2006

Dim rs As DAO.Recordset
With Forms!frmCC_Choice
Set rs = .RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs WHERE (((report_defs.Type) ="

&

"'C'" & ")) ORDER BY report_defs.DateModified DESC;"

This all works - nearly. I can open the form at the record I require

and

can then navigate the other records.
But the textbox bound to DateModified now shows #Error.

If I remove that sorting field from the recordsource then it displays

ok.

It's obviously the sorting that screws things up (but I need it sorted).

Is there a quick fix?



Your statement
Me.RecordSource = "SELECT report_defs.*, report_defs.Type,
report_defs.DateModified FROM report_defs

Why do you select Type and DateModified again. They should already be
selected in report_defs.*.


Ah good point.


Why are you setting the bookmark prior to code for finding the record?


Hmmm, the perils of copy/pasting code without understanding what it is. OK
so I should set the recordsource first then set the bookmark?

That would make sense to me. Otherwise you are finding the record first
in the existing recordsource then changing the recordsource thus wiping
out the find.

I noticed also when you are opening a form you pass a "usercode". Do
you use that? If not, you could pass the id of the record you are
searching for. Ex: On the OnOpen even

Me.RecordSource = "SELECT report_defs.*, report_defs.Type...
If Not IsNull(Me.OpenArgs) then
...code to find record in source
strWhere = "ID = " & Me.openargs
rs.FindFirst strWhere
...
endif

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.