Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?
From: Kahuna (none_at_gonewest.com)
Date: 12/17/04
- Next message: TomTait747: "RE: why is my OpenDatabase( "Filepath") command not working in access."
- Previous message: Marshall Barton: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- In reply to: Marshall Barton: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- Next in thread: Bas Cost Budde: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 17 Dec 2004 18:01:35 -0000
That's exactly what I need Marshal thanks - just couldn't get my head around
the FORMAT action/method.
I'll try that tonight thanks a lot.
-- Kahuna ------------ "Marshall Barton" <marshbarton@wowway.com> wrote in message news:lv56s0tte11f54nnjgtc7cp5k0siar8m5h@4ax.com... > Kahuna wrote: >>Following on from last nights disaster <lol> (Doug, John and Bas know what >>I >>mean) - I need some guidance on this one: >> >>I have an SQL Update statement (that works!!), which takes an input from a >>form to show which field to update in the table, a second input from the >>form which says update where 'x' is the current table entry, and a third >>input where the user types in what he'd like the data changed to. >> >>All works lovely in a text field in the table but fails dismally when >>there >>is a number / bool / date etc. >> >>I know the data type number of the field chosen to be updated, but cant >>find >>the way to set the SQL variables to assume the data types of the field. >>Here's the SQL string: >> >>strSQLUpdate = "UPDATE qryFabricCondition SET qryFabricCondition." & >>[txtField_to_Update] & " = " & "'" & txtUpdate_With & "'" & "" _ >> & " WHERE (qryFabricCondition." & >>[txtField_to_Update] & "= " & "'" & txt_Where_equal_to & "'" & ")" >> >>The variable txtUpdate_With is actually now Dim'd as a variant, thought >>this >>would allow it to assume the data type of the field to update to. >> >> Guess: Is it possible to set the form field to accept only a >>particular data type? >> Is it possible to set the variable to a specific data >> type >>before adding it to the SQL statement? >> I need to remove the extra quotes around the >>txtUpdate_With variable dependant upon the data type - >> This last seems most likely - but does that mean >>building the SQL on the fly or creating multiple copies of it (one for >>each >>type)? > > > You're already building the SQL on the fly. What you need > to do is take the type of the field to bu updated into > account. Here's some air code that should demonstrate the > idea: > > strSQLUpdate = "UPDATE qryFabricCondition " _ > & "SET " & [txtField_to_Update] & " = " _ > If <type of field is Text> Then > strSQLUpdate = strSQLUpdate _ > & "'" & txtUpdate_With & "'" _ > & " WHERE " & [txtField_to_Update] _ > & " = '" & txt_Where_equal_to & "'" > ElseIf <type of field is date> Then > strSQLUpdate = strSQLUpdate _ > & Format(txtUpdate_With, "\#m\/d\/yyyy\#") _ > & " WHERE " & [txtField_to_Update] _ > & " = " & Format(txt_Where_equal_to, "\#m\/d\/yyyy\#") > Else 'number type > strSQLUpdate = strSQLUpdate & txtUpdate_With _ > & " WHERE " & [txtField_to_Update] _ > & " = " & txt_Where_equal_to > End If > > -- > Marsh > MVP [MS Access]
- Next message: TomTait747: "RE: why is my OpenDatabase( "Filepath") command not working in access."
- Previous message: Marshall Barton: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- In reply to: Marshall Barton: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- Next in thread: Bas Cost Budde: "Re: Can't believe it - Back Again Already! - How to set variables to 'Type' in SQL Statement?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|