update query using like criteria

T

tina

Hi
I have a form with command button which runs a update query based on info in
form based on query
form prompts for stockcode and serial number . serial number is entered eg
*8aa* criteria in query criteria is like [enter serial number]
the update query sql is
UPDATE dbo_DataLots SET dbo_DataLots.StatusFlag = " "
WHERE (((dbo_DataLots.SerialNumber)like[Forms]![serial]![SerialNumber]));
each time i run it will only update one record ie first in form if do not
use like criteria will update all records but I need to be able to use like
is it possible?
Thanks
tina
 
D

Dale Fye

Tina,

What does the code in your command buttons click event look like?
Is this a linked SQL Server table that you are trying to update?

I would do something like:

Private Sub cmd_Update_Click

Dim strSQL as string

strSQL = "UPDATE dbo_DataLots " _
& "SET StatusFlag = ' ' " _
& "WHERE [SerialNumber] like '*" & me.SerialNumber & "*'"
currentdb.execute strsql, dbfailonerror

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
T

tina

Hi
my command button just runs update query which updates table
Private Sub cmd_Update_Click()
On Error GoTo Err_cmd_Update_Click

' Dim stDocName As String

' stDocName = "SERIAL UPDATE"
'DoCmd.SelectObject
' DoCmd.OpenQuery stDocName, acNormal, acEdit

'Exit_cmd_Update_Click:
' Exit Sub

'Err_cmd_Update_Click:
' MsgBox Err.Description
' Resume Exit_cmd_Update_Click

'End Sub
I tried your suggestion but still only updates selected record in form can i
write select all records if so how?
Thanks
Tina

Dale Fye said:
Tina,

What does the code in your command buttons click event look like?
Is this a linked SQL Server table that you are trying to update?

I would do something like:

Private Sub cmd_Update_Click

Dim strSQL as string

strSQL = "UPDATE dbo_DataLots " _
& "SET StatusFlag = ' ' " _
& "WHERE [SerialNumber] like '*" & me.SerialNumber & "*'"
currentdb.execute strsql, dbfailonerror

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



tina said:
Hi
I have a form with command button which runs a update query based on info in
form based on query
form prompts for stockcode and serial number . serial number is entered eg
*8aa* criteria in query criteria is like [enter serial number]
the update query sql is
UPDATE dbo_DataLots SET dbo_DataLots.StatusFlag = " "
WHERE (((dbo_DataLots.SerialNumber)like[Forms]![serial]![SerialNumber]));
each time i run it will only update one record ie first in form if do not
use like criteria will update all records but I need to be able to use like
is it possible?
Thanks
tina
 
D

Dale Fye

Tina,

First off, every line in your code is remared out (has an ' at the beginning
of the line), so nothing is going to happen.

Second, the OpenQuery method that you are using in your code will open a
Select query, but will not run an action (Update, Delete, Append) query. To
do that, you will either need to use the RunSQL method, or the Execute method
I gave you in my sample code.

My sample code assumes that you would enter a value like:8aa in the
SerialNumber field of your form. Keep in mind that this should be an unbound
field, not a bound field. If you are using a bound field for this, then you
will actually change the value of the field (I would actually call this
textbox txt_Criteria). If you want to be able to enter data like: *8aa* or
8aa* or something line that in the field where you are entering a value, then
change my code as follows:

WHERE [SerialNumber] Like '" & me.txt_Criteria & "'"

What is the SQL of the "Serial Update" query?
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



tina said:
Hi
my command button just runs update query which updates table
Private Sub cmd_Update_Click()
On Error GoTo Err_cmd_Update_Click

' Dim stDocName As String

' stDocName = "SERIAL UPDATE"
'DoCmd.SelectObject
' DoCmd.OpenQuery stDocName, acNormal, acEdit

'Exit_cmd_Update_Click:
' Exit Sub

'Err_cmd_Update_Click:
' MsgBox Err.Description
' Resume Exit_cmd_Update_Click

'End Sub
I tried your suggestion but still only updates selected record in form can i
write select all records if so how?
Thanks
Tina

Dale Fye said:
Tina,

What does the code in your command buttons click event look like?
Is this a linked SQL Server table that you are trying to update?

I would do something like:

Private Sub cmd_Update_Click

Dim strSQL as string

strSQL = "UPDATE dbo_DataLots " _
& "SET StatusFlag = ' ' " _
& "WHERE [SerialNumber] like '*" & me.SerialNumber & "*'"
currentdb.execute strsql, dbfailonerror

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



tina said:
Hi
I have a form with command button which runs a update query based on info in
form based on query
form prompts for stockcode and serial number . serial number is entered eg
*8aa* criteria in query criteria is like [enter serial number]
the update query sql is
UPDATE dbo_DataLots SET dbo_DataLots.StatusFlag = " "
WHERE (((dbo_DataLots.SerialNumber)like[Forms]![serial]![SerialNumber]));
each time i run it will only update one record ie first in form if do not
use like criteria will update all records but I need to be able to use like
is it possible?
Thanks
tina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top