Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The enviroment is simple, natural and efficient. The members are competent, educated and professionals..."

Geography

Where in the world do Tek-Tips members come from?

Text box value as query conditional. Syntax problem ?

MrJRW (IS/IT--Management)
28 Mar 12 9:51
Good Morning.

This one has me really, really, confused. (and frustrated !)

This "mdb" is to track warranty claims received.

Table 1:  tblClaimNumber, one field:  ClaimNumber.  Integer - defined as four (4) digits:  0001, 0002, etc

Table 2: tblWarrClaimLog   5 fields:

LogNumber (text)
DateReceived (Date)
Company (text)
Comments (text)
SEQ (number, integer)

On my data entry form I have ALL text boxes.

The LogNumber control (tbxLogNumber]is defaulted to a string of "WARR" & Year(Date()) & tblClaimNumber.ClaimNumber

The tblClaimNumber.[ClaimNumber] is sucessfully incremented when I leave the Comment text box, so the LogNumber changes for the next record

? I need to "copy" the tblClaimNumber.[ClaimNumber] value into the SEQ field of the other table.

This query DOES work:

UPDATE tblWarrClaimLog, tblClaimNumber
SET tblWarrClaimLog.[SEQ]= tblClaimNumber.[ClaimNumber]
WHERE tblWarrClaimLog.[LogNumber]='WARR-2012-0001'

So I just need to modify the WHERE conditional

Instead of the 'hard string' I'm trying to use the changing LogNumber string to direct the update to the proper record.

Using:
strLogNumber = Me.tbxLogNumber.Value, or
Forms![frmWARR_NewClaims]!tbxLogNumber]  instead of WARR-2012-0001

Does not work

? Any ideas ?

Thank-you for your help
MrJRW
MazeWorX (IS/IT--Management)
28 Mar 12 10:05
Try

Forms![frmWARR_NewClaims]![tbxLogNumber]

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>

MrJRW (IS/IT--Management)
28 Mar 12 10:33
Whoops ! Typo in my write up.

What I have coded is:

Dim strSQL As string

strSQL =
"UPDATE tblWarrClaimLog, tblClaimNumber " & _
"SET tblWarrClaimLog.[SEQ] = tblClaimNumber.[ClaimNumber] " & _
"WHERE tblWarrClaimLog.[LogNumber]= ' " & Forms![frmWarr_NewClaims]![tbxLogNumber] & " '; "

DoCmd.RunSQL strSQL
          
MazeWorX (IS/IT--Management)
28 Mar 12 11:30
Have you tried a debug.print to check the value of the control?

also

The LogNumber control (tbxLogNumber]is defaulted to a string of "WARR" & Year(Date()) & tblClaimNumber.ClaimNumber. Which would give you "WARR20120001" but the test data where the query works is 'WARR-2012-0001'

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>

MrJRW (IS/IT--Management)
28 Mar 12 11:37
MazeWorX,

Thank-you for trying to help me.

In the control for the Log Number, (tbxLogNumber) I set the Default value to:

="WARR-" & Year(Date()) & "-" & Format$(DLookup("[ClaimNumber]","tblClaimNumber"),"\0000")

Hence, the "-"s.

I don't know how to you debug.print

MrJRW
PHV (MIS)
28 Mar 12 12:16
You have spurious spaces here:
"WHERE tblWarrClaimLog.[LogNumber]= ' " & Forms![frmWarr_NewClaims]![tbxLogNumber] & " '; "

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

MrJRW (IS/IT--Management)
28 Mar 12 13:07
Mr. PHV,

Thank-you for your help.

Removed spaces.
Tested....

No joy

In my earlier post I ment to say I don't know how to use debug.print (not you debug.print)

Now you see why this issue has been vexing (great Scrabble word by-the-way) me !

Again, thank-you for your help

MrJRW

 
MazeWorX (IS/IT--Management)
28 Mar 12 15:10
add into your code

debug.print Me.tbxLogNumber

It should print the value of the control in the immediate window when the code is executed

or even a debug.print strSQL will print the SQL  

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>

MrJRW (IS/IT--Management)
28 Mar 12 16:39
My Sub:

Private Sub tbxNameofParty_Exit(Cancel As Integer)

Dim strSQL As String
Dim strLogNumber As String

strLogNumber = Me.tbxLogNumber.Value

strSQL = "UPDATE tblWarrClaimLog, tblClaimNumber " & _
            "SET tblWarrClaimLog.[SEQ] = tblClaimNumber.[ClaimNumber] " & _
            "WHERE tblWarrClaimLog.[LogNumber]= '" & Forms![frmWARR_NewClaims]![tbxLogNumber] & "';"
            
            
Debug.Print Me.tbxLogNumber
            
            
            
'     This did not work              "WHERE tblWarrClaimLog.[LogNumber]= '" & strLogNumber & "';"
'     This works when hardwired      "WHERE tblWarrClaimLog.[LogNumber]= 'WARR-2012-0001';"


    
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True



End Sub

Adding in the debug.print Me.tbxLogNumber or debug.print strSQl did nothing

JRW
MazeWorX (IS/IT--Management)
28 Mar 12 19:23
ok obviously we are having an issue with your familiarity with the vbe interface so ... lets add this instead of the debug


MsgBox strSQL

this should pop the SQL up as a msg box copy the text and paste it here

also add the line

MsgBox  Me.tbxLogNumber.Value

and post it just for fun

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>

MrJRW (IS/IT--Management)
29 Mar 12 15:27
This is too weird.

The MsgBox for strSQL yields:

UPDATE tblWarrClaimLog, tblClaimNumber SET tblWarrClaimLog.[SEQ] = tblClaimNumber.[ClaimNumber] WHERE tblWarrClaimLog.[LogNumber]='WARR-2012-0090';

ClaimNumber was at 0090 when I ran this.

The MsgBox for Me.tbxLogNumber.Value gave:

WARR-2012-0090

BUT !!!

the value of tblWarrClaimLog.[SEQ] is still 0 !

So if I hardcode the stuff between the single quotes, [SEQ] gets set to the correct value (90), but If I use some type of "variable", (i.e. the value of the control), [SEQ] does not get updated.

Weird.

JRW
MazeWorX (IS/IT--Management)
29 Mar 12 16:15
A possible solution would be to get the value from the control?


SET tblWarrClaimLog.[SEQ] = Right(Me.tbxLogNumber,4)

Also for testing comment out the SetWarnings lines so we can see how the query is giving errors. Try it as is first with warnings commented out

thoughts?

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>

MrJRW (IS/IT--Management)
8 Apr 12 22:01
Problem solved

I was setting the value of LogNumber via the Default Value property

When I changed to setting the value of Me.LogNumber.Value in an event (LogNumber_GotFocus), the update query worked !

Thank-you all who helped.

MrJRW

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close