Need help with DoCmd.FindRecord

G

Guest

Hi all,

I need some help with the DoCmd.FindRecord function. I’m working with two
forms both of which have the table ‘data’ as it’s record source. What I’m
trying to do is click a command button on the first form and have the second
form load with the same record as the first form. What happens with out my
code is the second form loads with the data of the first record in the record
set. The field that I’m working with is ‘Institution’. The first form is
called ‘Form1’ and the second form is called ‘Budget’. The code is put into
the Form load event of the form ‘Budget’. I’ve been able to get the variable
to match the institution in the record in ‘Form1’. When the
Do.Cmd.FindRecord runs, I get the error number 2046: The command or action
“FindRecord†isn’t available now. – you may be in a read-only database or an
unconverted database from an earlier version of MS Access. – the type of
object the action applies to isn’t currently selected or isn’t in the active
view.

Also, I checked that the records lock property of both forms is set to No
Locks.

Here is my code:

Dim txtInstitutionName As TextBox
Set txtInstitutionName = Forms("Form1").txtInstitution
Institution.SetFocus

DoCmd.FindRecord "[Institution]= " & txtInstitutionName

Any help is greatly appreciated.

Mark
 
A

Allan Murphy

Mark

What is the purpose of the Form1?
1. If it is used to lookup data for BUDGET form then on the BUDGET form
you could use a combo box to find the record from the drop down list of
Institutions you will not require form1.

Also if you change data on form1 it will not be shown on BUDGET form until
you save the current record.

Looking at you coding try
Set txtInstitutionName = forms!form1!.txtInstitution



Allan Murphy
(e-mail address removed)
 
G

Guest

Allan,

Form1 is a form with four pages. It provides data from the ‘data’ table and
it is editable. The form ‘Budget’ provides a large amount of data for one
record and it is editable. Its record source is the ‘data’ table. I suspect
that the Budget form was created because ‘Form1’ could not hold all the data
without making substantial changes in the user interface.

I tried setting txtInstitutionName = Forms!Form1!.txtInstitution like you
suggested, however I got the same 2046 error as before. I could be wrong,
but I don’t think my problem is setting the variable. When I put a
breakpoint in, run the code, and examine the variable txtInstitutionName, it
holds the correct string value in both the method you suggested and the code
I wrote before.

Here is the error that I get when I run the code:
“Run-time error ‘2046’:

The command or action ‘FindRecord’ isn’t available now.

*You may be in a read-only database or an unconverted database from an
earlier version of MS Access.
*The type of object the action applies to isn’t currently selected or isn’t
in the active view.

Use only those commands and macro actions that are currently available for
this database.â€

Do I have to call the set focus event on one of the controls on the Budget
form? I’ve been trying to set focus to the Budget from without success.

Thanks for your help!

Mark


Allan Murphy said:
Mark

What is the purpose of the Form1?
1. If it is used to lookup data for BUDGET form then on the BUDGET form
you could use a combo box to find the record from the drop down list of
Institutions you will not require form1.

Also if you change data on form1 it will not be shown on BUDGET form until
you save the current record.

Looking at you coding try
Set txtInstitutionName = forms!form1!.txtInstitution



Allan Murphy
(e-mail address removed)
Mark B said:
Hi all,

I need some help with the DoCmd.FindRecord function. I'm working with two
forms both of which have the table 'data' as it's record source. What I'm
trying to do is click a command button on the first form and have the second
form load with the same record as the first form. What happens with out my
code is the second form loads with the data of the first record in the record
set. The field that I'm working with is 'Institution'. The first form is
called 'Form1' and the second form is called 'Budget'. The code is put into
the Form load event of the form 'Budget'. I've been able to get the variable
to match the institution in the record in 'Form1'. When the
Do.Cmd.FindRecord runs, I get the error number 2046: The command or action
"FindRecord" isn't available now. - you may be in a read-only database or an
unconverted database from an earlier version of MS Access. - the type of
object the action applies to isn't currently selected or isn't in the active
view.

Also, I checked that the records lock property of both forms is set to No
Locks.

Here is my code:

Dim txtInstitutionName As TextBox
Set txtInstitutionName = Forms("Form1").txtInstitution
Institution.SetFocus

DoCmd.FindRecord "[Institution]= " & txtInstitutionName

Any help is greatly appreciated.

Mark
 
G

Guest

Allan,

I’ve been trying different methods and tinkering around with what I had.
Finally, I got everything to work how I wanted it to. Here is the code that
I used to open the second form (Budget) with the same record as the first
form (Form1).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Load()
On Error GoTo Err_Form_Load

Dim strCriteria As String
Dim txtInstitutionName As TextBox
Dim rstData As Recordset


Set txtInstitutionName = Forms("Form1").txtInstitution
strCriteria = "[Institution] = '" & txtInstitutionName & "'"
Set rstData = Me.RecordsetClone

rstData.FindFirst strCriteria
Me.Bookmark = rstData.Bookmark

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~

I just couldn’t figure out a way to get around the 2046 error with still
using the DoCmd.FindRecord.

Thanks again for your time,

Mark


Mark B said:
Allan,

Form1 is a form with four pages. It provides data from the ‘data’ table and
it is editable. The form ‘Budget’ provides a large amount of data for one
record and it is editable. Its record source is the ‘data’ table. I suspect
that the Budget form was created because ‘Form1’ could not hold all the data
without making substantial changes in the user interface.

I tried setting txtInstitutionName = Forms!Form1!.txtInstitution like you
suggested, however I got the same 2046 error as before. I could be wrong,
but I don’t think my problem is setting the variable. When I put a
breakpoint in, run the code, and examine the variable txtInstitutionName, it
holds the correct string value in both the method you suggested and the code
I wrote before.

Here is the error that I get when I run the code:
“Run-time error ‘2046’:

The command or action ‘FindRecord’ isn’t available now.

*You may be in a read-only database or an unconverted database from an
earlier version of MS Access.
*The type of object the action applies to isn’t currently selected or isn’t
in the active view.

Use only those commands and macro actions that are currently available for
this database.â€

Do I have to call the set focus event on one of the controls on the Budget
form? I’ve been trying to set focus to the Budget from without success.

Thanks for your help!

Mark


Allan Murphy said:
Mark

What is the purpose of the Form1?
1. If it is used to lookup data for BUDGET form then on the BUDGET form
you could use a combo box to find the record from the drop down list of
Institutions you will not require form1.

Also if you change data on form1 it will not be shown on BUDGET form until
you save the current record.

Looking at you coding try
Set txtInstitutionName = forms!form1!.txtInstitution



Allan Murphy
(e-mail address removed)
Mark B said:
Hi all,

I need some help with the DoCmd.FindRecord function. I'm working with two
forms both of which have the table 'data' as it's record source. What I'm
trying to do is click a command button on the first form and have the second
form load with the same record as the first form. What happens with out my
code is the second form loads with the data of the first record in the record
set. The field that I'm working with is 'Institution'. The first form is
called 'Form1' and the second form is called 'Budget'. The code is put into
the Form load event of the form 'Budget'. I've been able to get the variable
to match the institution in the record in 'Form1'. When the
Do.Cmd.FindRecord runs, I get the error number 2046: The command or action
"FindRecord" isn't available now. - you may be in a read-only database or an
unconverted database from an earlier version of MS Access. - the type of
object the action applies to isn't currently selected or isn't in the active
view.

Also, I checked that the records lock property of both forms is set to No
Locks.

Here is my code:

Dim txtInstitutionName As TextBox
Set txtInstitutionName = Forms("Form1").txtInstitution
Institution.SetFocus

DoCmd.FindRecord "[Institution]= " & txtInstitutionName

Any help is greatly appreciated.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top