dbTalk Databases Forums  

help with VB DoDmd.OpenForm WhereCondition

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


Discuss help with VB DoDmd.OpenForm WhereCondition in the comp.databases.ms-access forum.



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

Default help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:20 AM






I am trying to build an Access 2002/2003 database application that I
would like to offer to other writers so they can track submissions.
Just trying to make a helpful tool for writers, poets, or anyone who
submits anything to anywhere, actually... I'm having trouble with the
Visual Basic code for the on click event of a button.

So, I have a form, FormA, whose source is a query. On FormA, there is
a numeric field called FieldA. FieldA corresponds to the primary key
(numeric) of the source table for FormB. On FormB, that same related
field is called FieldB.

I have a button on FormA called ButtonA. When clicked, ButtonA should
open FormB to the record in FormB where FieldB is the same as the
value of FieldA on the record where ButtonA was clicked.

The code that is not working is:
_________________________________________________
Private Sub ButtonA_Click()
CoCmd.OpenForm "FormB",,, FormB.FieldB = FormA.FieldA
End Sub
__________________________________________________

With this, I get Run-time error '424'. Object Required.

I read that "the WhereCondition is just an sql where statement without
the WHERE", but apparently, there is some other syntax or structure I
am missing. Any help greatly appreciated. Thanks!

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

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:28 AM






Try ....
CoCmd.OpenForm "FormB",,, "Forms!FormB.FieldB = " & Me.FieldA

Steve

"rik" <efelthauser (AT) gmail (DOT) com> wrote

Quote:
I am trying to build an Access 2002/2003 database application that I
would like to offer to other writers so they can track submissions.
Just trying to make a helpful tool for writers, poets, or anyone who
submits anything to anywhere, actually... I'm having trouble with the
Visual Basic code for the on click event of a button.

So, I have a form, FormA, whose source is a query. On FormA, there is
a numeric field called FieldA. FieldA corresponds to the primary key
(numeric) of the source table for FormB. On FormB, that same related
field is called FieldB.

I have a button on FormA called ButtonA. When clicked, ButtonA should
open FormB to the record in FormB where FieldB is the same as the
value of FieldA on the record where ButtonA was clicked.

The code that is not working is:
_________________________________________________
Private Sub ButtonA_Click()
CoCmd.OpenForm "FormB",,, FormB.FieldB = FormA.FieldA
End Sub
__________________________________________________

With this, I get Run-time error '424'. Object Required.

I read that "the WhereCondition is just an sql where statement without
the WHERE", but apparently, there is some other syntax or structure I
am missing. Any help greatly appreciated. Thanks!



Reply With Quote
  #3  
Old   
Allen Browne
 
Posts: n/a

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:31 AM



You need quotes. The WhereCondition is a string.

Ultimately you need it to read something like this:
FieldB = 999
so code like this:

Private Sub ButtonA_Click()
Dim strWhere as String
If Me.Dirty Then Me.Dirty = False
If IsNull(Me.FieldA) Then
MsgBox "There's no FieldA value."
Else
strWhere = "FieldB = " & Me.FieldA
DoCmd.OpenForm "FormB", WhereCondition:=strWhere
End If
End Sub

--
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.

"rik" <efelthauser (AT) gmail (DOT) com> wrote

Quote:
I am trying to build an Access 2002/2003 database application that I
would like to offer to other writers so they can track submissions.
Just trying to make a helpful tool for writers, poets, or anyone who
submits anything to anywhere, actually... I'm having trouble with the
Visual Basic code for the on click event of a button.

So, I have a form, FormA, whose source is a query. On FormA, there is
a numeric field called FieldA. FieldA corresponds to the primary key
(numeric) of the source table for FormB. On FormB, that same related
field is called FieldB.

I have a button on FormA called ButtonA. When clicked, ButtonA should
open FormB to the record in FormB where FieldB is the same as the
value of FieldA on the record where ButtonA was clicked.

The code that is not working is:
_________________________________________________
Private Sub ButtonA_Click()
CoCmd.OpenForm "FormB",,, FormB.FieldB = FormA.FieldA
End Sub
__________________________________________________

With this, I get Run-time error '424'. Object Required.

I read that "the WhereCondition is just an sql where statement without
the WHERE", but apparently, there is some other syntax or structure I
am missing. Any help greatly appreciated. Thanks!

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

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:42 AM



Thanks for the suggestion Steve. But that was only able to open FormB,
not showing the corresponding record. Actually the form opens filtered
to a single empty record...


On Oct 14, 10:28*am, "Steve" <nonse... (AT) nomsense (DOT) com> wrote:
Quote:
Try ....
CoCmd.OpenForm "FormB",,, "Forms!FormB.FieldB = " & Me.FieldA

Steve

"rik" <efelthau... (AT) gmail (DOT) com> wrote in message

news:1bf9319c-1a87-4780-b3d8-8bc66d7e0d39 (AT) q35g2000hsg (DOT) googlegroups.com...


Reply With Quote
  #5  
Old   
Marshall Barton
 
Posts: n/a

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:50 AM



rik wrote:

Quote:
I am trying to build an Access 2002/2003 database application that I
would like to offer to other writers so they can track submissions.
Just trying to make a helpful tool for writers, poets, or anyone who
submits anything to anywhere, actually... I'm having trouble with the
Visual Basic code for the on click event of a button.

So, I have a form, FormA, whose source is a query. On FormA, there is
a numeric field called FieldA. FieldA corresponds to the primary key
(numeric) of the source table for FormB. On FormB, that same related
field is called FieldB.

I have a button on FormA called ButtonA. When clicked, ButtonA should
open FormB to the record in FormB where FieldB is the same as the
value of FieldA on the record where ButtonA was clicked.

The code that is not working is:
_________________________________________________
Private Sub ButtonA_Click()
CoCmd.OpenForm "FormB",,, FormB.FieldB = FormA.FieldA
End Sub
__________________________________________________

With this, I get Run-time error '424'. Object Required.

I read that "the WhereCondition is just an sql where statement without
the WHERE", but apparently, there is some other syntax or structure I
am missing. Any help greatly appreciated. Thanks!

The WhereCondition argument is a string, not an expression.
The string usually contains an expression, but you need to
enclose it in quotes and/or concatenate values that results
in a string. Your FormB.FieldB has invalid syntax and is
not in quotes. In addition, you need to refer to **fields**
in FormB's record source table/query, not to controls on the
form.

Assuming that FieldA is a numeric type field, use:

DoCmd.OpenForm "FormB",,, "FieldB = " & Me.FieldA

If FieldA is a Text field, then use:

DoCmd.OpenForm "FormB",,, "FieldB = """ & Me.FieldA & """"

If FieldA is a Date field, then use:

DoCmd.OpenForm "FormB",,, "FieldB = " _
& Format(Me.FieldA, "\#yyyy-m-d\#")

--
Marsh


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

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:55 AM



Allen, your code worked Perfectly! Thank you so much. You are really
awesome. I'll try to learn VB myself one of these days.


On Oct 14, 10:31*am, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid>
wrote:
Quote:
You need quotes. The WhereCondition is a string.

Ultimately you need it to read something like this:
* * FieldB = 999
so code like this:

* * Private Sub ButtonA_Click()
* * * * Dim strWhere as String
* * * * If Me.Dirty Then Me.Dirty = False
* * * * If IsNull(Me.FieldA) Then
* * * * * * MsgBox "There's no FieldA value."
* * * * Else
* * * * * * strWhere = "FieldB = " & Me.FieldA
* * * * * * DoCmd.OpenForm "FormB", WhereCondition:=strWhere
* * * * End If
* * End Sub

--
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.



Reply With Quote
  #7  
Old   
rik
 
Posts: n/a

Default Re: help with VB DoDmd.OpenForm WhereCondition - 10-14-2008 , 10:58 AM



Wow. So many responses before I can even reply with success. I'll read
though the others and try to learn from them too. Thanks to everyone
again. I'll try to remember to post a link to the database here once
it's whipped into shape.

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.