Re: syntax problems
- From: "Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx>
- Date: Sat, 20 Aug 2005 07:07:06 -0400
Yeah, that's what I get for just copying your original code!
It's complaining about your use of .Value.
Fortunately, the other version I posted (which omits both the .Value and
..Text properties) will work, since in all cases the default property is the
one you want.
IngMyVar = Nz(DlookUp("idnTimeCardID", "tblTimeCardID", _
"idnEmployeeID=" & txtEmployeeID & " AND " & _
"chrMonth=" & Chr$(34) & cboMonth & Chr$(34) & _
" AND sngYear=" & cboYear),0)
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"slowuptake" <slowuptake@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0366A48A-2ABC-474A-A979-C195DFDAFE36@xxxxxxxxxxxxxxxx
>I used your second variant below, as it is clear that cboMonth is returning
> the name of the month.
>
> When I step through the code, the compiler kicks out to
> Err_cmdFindTimeSheet, and gives the message:
>
> "You can't reference a property or method of control unless the control
> has
> the focus".
>
> I presume this means I need to use something like the SetFocus command,
> but
> I'm not sure what needs the focus.
>
> regards,
> slowuptake
>
> "Douglas J. Steele" wrote:
>
>> The & in the first line isn't required but there are some additional ones
>> required on the other lines, you need spaces around the words AND and
>> you're
>> missing the equal sign after sngYear. It should be:
>>
>> IngMyVar = Nz(DlookUp("idnTimeCardID", "tblTimeCardID", _
>> "idnEmployeeID=" & txtEmployeeID.Value & " AND " & _
>> "chrMonth=" & cboMonth.Text & " AND " & _
>> "sngYear=" & cboYear.Value ),0)
>>
>> Of course, as Ron implied, this will only work if all three values are
>> numeric. If they're text, you need to include quote marks around the
>> values.
>> For instance, if cboMonth.Text does return the name of the month, rather
>> than the number, you'd use:
>>
>> IngMyVar = Nz(DlookUp("idnTimeCardID", "tblTimeCardID", _
>> "idnEmployeeID=" & txtEmployeeID.Value & " AND " & _
>> "chrMonth=" & Chr$(34) & cboMonth.Text & Chr$(34) & _
>> " AND sngYear=" & cboYear.Value ),0)
>>
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>>
>> "slowuptake" <slowuptake@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:2FDB8A4C-1286-4512-9C2D-0568AC9F6E44@xxxxxxxxxxxxxxxx
>> > Ron,
>> >
>> > Thanks for that, considerably more elegant than what I was attempting.
>> > Here is how I tried translate your instructions:
>> >
>> > IngMyVar = Nz(DlookUp("idnTimeCardID", "tblTimeCardID", & _
>> > "idnEmployeeID=" & txtEmployeeID.Value & "AND" _
>> > "chrMonth=" & cboMonth.Text & "AND" _
>> > "sngYear" & cboYear.Value ),0)
>> >
>> > I must have something slightly wrong however, as this causes compiler
>> > to
>> > respond with a syntax error as soon as I type in the expression.
>> >
>> > regards,
>> > slowuptake
>> >
>> > "Ron Weiner" wrote:
>> >
>> >> You can get started by looking in Access Help for DlookUp() function.
>> >> You
>> >> may also want to have a look at the Nn() function. There is no need
>> >> to
>> >> store the values of the combo boxes in variables since you can access
>> >> them
>> >> directly in an expression. There is no need to search the table row
>> >> by
>> >> row.
>> >> Let the Dlookup() function find the row and retrieve the value for
>> >> you.
>> >>
>> >> Sounds like a:
>> >>
>> >> Private Sub cmdYourButton_Click()
>> >> Dim lngMyVar as Long
>> >>
>> >> lngMyVar = Nz(DlookUp("Column1Name", "TableWith4Columns", & _
>> >> "Colum2Name=" & Combo1.Value & "AND " _
>> >> "Colum3Name=" & Combo2.Value & "AND " _
>> >> "Colum4Name=" & Combo3.Value ),0)
>> >> ' Use lngMyVar any way you like below
>> >> End Sub
>> >>
>> >> The above assumes that the all of the columns in the table hole
>> >> numeric
>> >> values. You will need to modify the above to handle any columns that
>> >> are
>> >> strings or dates.
>> >>
>> >>
>> >> Ron W
>> >> www.WorksRite.com
>> >> "slowuptake" <slowuptake@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> >> news:3AAC43BB-A132-4953-B92D-04FF59F84D85@xxxxxxxxxxxxxxxx
>> >> > I am trying to add some code to a button placed in a form, but I'm
>> >> > new
>> >> > to
>> >> > visual basic programming in Access, and am having troubles with
>> >> > syntax.
>> >> >
>> >> > Perhaps someone could drop me a snippet of code to get me started??
>> >> >
>> >> > What I'm trying to do is:
>> >> >
>> >> > 1) when button is pushed, code reads in 3 variables from combo boxes
>> >> > in
>> >> form
>> >> >
>> >> > 2) using these three variables, read row by row (record by record)
>> >> > through
>> >> a
>> >> > 4 column (field) table, and select the unique record there the
>> >> > values
>> >> > in
>> >> the
>> >> > last 3 columns match the 3 variables
>> >> >
>> >> > 3) retrieve the value of the first column (the record number/primary
>> >> > key)
>> >> > that identifies the unique row (record)
>> >> >
>> >> > The ultimate goal is to use this record number to sort data in a
>> >> > subform
>> >> > that I have ready, but not yet moved into the main form.
>> >> >
>> >> > regards,
>> >> > slowuptake
>> >>
>> >>
>> >>
>>
>>
>>
.
- Follow-Ups:
- Re: syntax problems
- From: slowuptake
- Re: syntax problems
- References:
- syntax problems
- From: slowuptake
- Re: syntax problems
- From: Ron Weiner
- Re: syntax problems
- From: slowuptake
- Re: syntax problems
- From: Douglas J. Steele
- Re: syntax problems
- From: slowuptake
- syntax problems
- Prev by Date: Re: syntax problems
- Next by Date: Re: Tab Control
- Previous by thread: Re: syntax problems
- Next by thread: Re: syntax problems
- Index(es):
Relevant Pages
|