Openning a form to a specific record first

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If
 
I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

Klatuu said:
Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

GL said:
Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


GL said:
I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

Klatuu said:
Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

GL said:
Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
When I open the Cost form by its own and not through the procedure I get an
"invalid use of null error" message. What I do in this case?

Klatuu said:
No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


GL said:
I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

Klatuu said:
Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

:

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Do you mean opening the form from the database window?

GL said:
When I open the Cost form by its own and not through the procedure I get an
"invalid use of null error" message. What I do in this case?

Klatuu said:
No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


GL said:
I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

:

Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

:

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Exactly, because in this case the strItem string is null I get this error
message

Klatuu said:
Do you mean opening the form from the database window?

GL said:
When I open the Cost form by its own and not through the procedure I get an
"invalid use of null error" message. What I do in this case?

Klatuu said:
No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


:

I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

:

Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

:

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Then change this line:
strItem = Me.OpenArgs
To this:
strItem = Nz(Me.OpenArgs,"")

GL said:
Exactly, because in this case the strItem string is null I get this error
message

Klatuu said:
Do you mean opening the form from the database window?

GL said:
When I open the Cost form by its own and not through the procedure I get an
"invalid use of null error" message. What I do in this case?

:

No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


:

I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

:

Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

:

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Your help is very much appreciated
Thanks

Klatuu said:
Then change this line:
strItem = Me.OpenArgs
To this:
strItem = Nz(Me.OpenArgs,"")

GL said:
Exactly, because in this case the strItem string is null I get this error
message

Klatuu said:
Do you mean opening the form from the database window?

:

When I open the Cost form by its own and not through the procedure I get an
"invalid use of null error" message. What I do in this case?

:

No. Change your code to this:
DoCmd.OpenForm "Cost", , , , , , Me!ItemCode
You can look up info on OpenArgs in VBA Help. Also look up OpenForm

The code I posted belongs in the Form Load event of the Cost form you are
opening.


:

I have not exactly understood because I am not familiar to to OpenArgs
property, do I have to put the code you have suggested after my code?

:

Use the OpenArgs arugment to pass the item code to the Cost form. The use
the FindFirst method to position the recordset in Cost's Form Load event:

strItem = Me.OpenArgs
If Len(strItem) <> 0 Then
strWhere = "[Item Code] = '" & strItem & "'"
Set rst = Me.RecordsetClone
rst.FindFirst strWhere
If rst.NoMatch Then
MsgBox "Item Code " & strItem & " Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End If

:

Hi,

I want to open a form in Continuous Forms view and have a specific record
first then the subsequent records following. I get the value of a field named
[ItemCode] from another form that is already open and I have used the code :
DoCmd.OpenForm "Cost", , , "[ItemCode] = '" & Me!ItemCode & "'"
to open it but what I get is the form showing only a specific record.
Do you know a way to get the form as I want?

Thanks
GL
 
Back
Top