Rabu, 21 Maret 2012

[MS_AccessPros] Re: Cannot Solve a Simple OpenForm Problem

 

Bill\Duane:

Thanks for the additional info. I looked at it again. It works but I don't understand why. When I was trying to figure out what as happening I set a watch on "AirCraftID". The AircraftID I doubleclicked always showed up as the value.. The form opened but the filter was always for the second AircraftId in the source table.

To try to figure out what is going on I just added a second DoCmd line in the code. I substituted Duane's string in the DoCmd line. I then ran the sequence with one or the other of the DoCmd lines commented out. Both watches showed the same result, the value was whatever the doubleclicked AicraftID was (in quotes) and the type was Object/TextBox. Yet one works and the other does not.

Bill's comment about Access needing the quotes when reading in the "WHERE" to properly interpret it as a string must be the answer.

Again, thank you both.

Jack

--- In MS_Access_Professionals@yahoogroups.com, "Duane" <duanehookom@...> wrote:
>
> I have a tendency to create string variables for where clauses and in lots of other situations. This helps me understand and control my code better. It also breaks apart code into smaller more manageable chunks. I can also set a break point and step through more easily to see what is going on in my code.
>
> Duane
>
> --- In MS_Access_Professionals@yahoogroups.com, "Bill Mosca" <wrmosca@> wrote:
> >
> > Jack -
> > Of course everyone knows!
> >
> > Just kidding. The code you used was:
> > DoCmd.OpenForm "frmTenantInput", acNormal, , [AircraftID] = Forms![frmTenantInfo]![AircraftID], , acDialog
> >
> > If you look at what the WhereCondition really is you might understand why it ran without errors but failed to do what you wanted.
> >
> > This line:
> > [AircraftID] = Forms![frmTenantInfo]![AircraftID]
> >
> > will always return True since it's just two ways of saying the same thing, AricraftID. So your WhereCondition is the same thing as saying -1 = -1. All that's going to do is get all records.
> >
> > If you put your cursor on OpenForm and press F1 the help file will open to that entry. Note the WhereCondition is a string. All strings must be in quotes so the compiler knows they are literals.
> >
> > Going further, you have to use Forms![frmTenantInfo]![AircraftID] as a variable. You can't use it in VBA and have it evaluated properly. That's why its value is concatenated to the string and not used directly in the string.
> >
> > Regards,
> > Bill Mosca, Founder - MS_Access_Professionals
> > http://www.thatlldoit.com
> > Microsoft Office Access MVP
> > https://mvp.support.microsoft.com/profile/Bill.Mosca
> >
> >
> >
> > --- In MS_Access_Professionals@yahoogroups.com, "robsonjack" <robsonjack@> wrote:
> > >
> > > Duane:
> > >
> > > Thanks. That works very nicely. But why didn't my approach work? I had previously tried a string similar to yours in the DoCmd OpenForm line. The examples in Access (and in the Microsoft developer forum) never mention having to declare a string outside that cmd. Was that one of those everyone knows that things?
> > > Jack
> > >
> > > --- In MS_Access_Professionals@yahoogroups.com, "Duane" <duanehookom@> wrote:
> > > >
> > > > Change your code to:
> > > > Dim strWhere as String
> > > > strWhere = "[AircraftID] = '" & Me.AircraftID & "'"
> > > > DoCmd.OpenForm "frmTenantInput", acNormal, , strWhere, , acDialog
> > > >
> > > > Duane Hookom
> > > > MS Access MVP
> > > >
> > > > --- In MS_Access_Professionals@yahoogroups.com, "robsonjack" <robsonjack@> wrote:
> > > > >
> > > > > I'm sure I'm missing something simple but any help would be greatly appreciated. I cannot get the "where" portion of OpenForm ... to work. I've uploaded a file called Troubleshooting11 to the downloads section. You have no idea how long I've messed with this.
> > > > >
> > > > > Thanks for any help.
> > > > >
> > > > > Jack
> > > > >
> > > >
> > >
> >
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar