Re: Open a form at a specific record

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes sorry, I see my mistake, it works fine, thank you very much.

Is there anything simple I can add to the code to close the original form
before opening the next one? I want my database to work a bit like a website
with buttons to navigate from one place to another, without a load of forms
left open.
--
Hagan


"Allen Browne" wrote:

Your quotes do not match what we suggested for you to type in.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Hagan" <Hagan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:96A91E61-0A8D-45D6-AFF7-CAF2FBFF82BB@xxxxxxxxxxxxxxxx
As I write in: strWhere = "[actual club] = "blue
I am interupted, this line goes red, with the top line: Private Sub SDB
Click () becoming highlighted
and I get error message Compile error: Expected: end of statement.
This is the full code I am putting in, including the first two lines which
are already there before I start.

Private Sub SDB_Click()
On Error GoTo Err_SDB_Click
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False 'save first.
If Not IsNull(Me.[actual club]) Then
strWhere ="[actual club]= "blue and whites"
DoCmd.OpenForm "registered clubs", WhereCondition:=strWhere
End If

--
Hagan


"Hagan" wrote:

Thank you, but I did warn you I am a beginner!

I assume I enter this by going to "Build Event" for the button. But I am
not sure where in the code you have written I put the name of the form to
be
opened, the field of the record to search and the actual name in that
particular field on to produce the particular record. Below I have used
"registered clubs" for the name of the form, "actual club" for the name
of
the field and "blue and whites" for the entry in the field for the record
that I am trying to produce, in the code that you gave me, but it doesn't
work so I am obviously not got the names in the right places.

Dim strWhere As String
If Me.Dirty Then Me.Dirty = False 'save first.
If Not IsNull(Me.[actual club]) then
strWhere = "[actual club] = " & Me.[blue and whites]
DoCmd.OpenForm "[registered clubs]", WhereCondition:=strWhere
End If

I have tried various permutations without success. With the above I get
error message "Access can't find field '|' referred to in your
expression.

Any ideas?

--
Hagan


"Allen Browne" wrote:

Unless the target form is already open, you can open it filtered to
just the
one record by using the WhereCondition argument of OpenForm.

For example, if you have a Number field named ID:

Dim strWhere As String
If Me.Dirty Then Me.Dirty = False 'save first.
If Not IsNull(Me.ID) then
strWhere = "ID = " & Me.ID
DoCmd.OpenForm "Form2", WhereCondition:=strWhere
End If

If you acutally want to open the form unfiltered, but move to the
desired
record, use FindFirst on the RecordsetClone of the form, and then match
bookmark.

Either way, the WhereCondition or FindFirst string is anything that you
could validly put in the WHERE clause of a query.

"Hagan" <Hagan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:12DC6589-3743-4B99-AD0E-72263AB32F03@xxxxxxxxxxxxxxxx
This is probably simple, but I am a bit of a beginner. I am trying
to
create
a button on a form - which I use as an opening men for the database -
that
will open another form at a specific record. The forms hold the
records
of
various organisations and their names are the primary key. I know
how to
build queries to get specific information, but not how to open an
entire
form
at a specific record.



.



Relevant Pages

  • Re: Open a form at a specific record
    ... Allen Browne - Microsoft MVP. ... Tips for Access users - http://allenbrowne.com/tips.html ... and I get error message Compile error: Expected: end of statement. ... Dim strWhere As String ...
    (microsoft.public.access.queries)
  • Re: Problem with Date code syntax
    ... > format the dates as expected by JET. ... > Allen Browne - Microsoft MVP. ... >> Dim strwhere As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: ByRef Argument Type Mismatch?
    ... Public Sub OpenFormAndClosePrevious(stDocName As String, ... Allen Browne - Microsoft MVP. ... Public Sub OpenFormAndClosePrevious(stDocName As String, ... error message "ByRef Argument Type Mismatch" with no meaningful help. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Open a form at a specific record
    ... I am interupted, this line goes red, with the top line: Private Sub SDB ... and I get error message Compile error: Expected: end of statement. ... Dim strWhere As String ...
    (microsoft.public.access.queries)
  • Re: select between dates
    ... Dim strWhere As String ... Allen Browne - Microsoft MVP. ... please tell me what the code should be to select this, i can filter ...
    (microsoft.public.access.tablesdbdesign)