Insert into field in current record (2 Viewers)

Mclaren

Registered User.
Local time
Today, 02:54
Joined
Mar 28, 2007
Messages
13
I would like to be able to insert data into a field in a table in an existing record.

I need to be able to do this using VB, but am not sure how to. I know how to delete a record and how to add a record, but not how to modify 1 field in an existing table.

Any help greatly appreciated.
 

MStef

Registered User.
Local time
Today, 10:54
Joined
Oct 28, 2004
Messages
2,251
Try to do it via UPDATE QUERY.
 

Mclaren

Registered User.
Local time
Today, 02:54
Joined
Mar 28, 2007
Messages
13
Must be VB.
 

JANR

Registered User.
Local time
Today, 11:54
Joined
Jan 21, 2009
Messages
1,623
Code:
Dim strSQL As Sting
strSQL = " UPDATE tblname SET FieldInQuestion = something WHERE RecID = Something"
Currentdb.Execute strSQL

JR
 

Mclaren

Registered User.
Local time
Today, 02:54
Joined
Mar 28, 2007
Messages
13
thank you.

I am getting a runtime error 3601

my code as follows:
Private Sub txtUnlockCode_AfterUpdate()

Dim UnlockCheck As String
Dim strSQL As String
Dim strActivationResult As String
strResult = "yes"
UnlockCheck = (strUnlockCode / 351) - 1974

If Me.txtUnlockCode = strUnlockCode Then
MsgBox "Activation Successfull" & _
vbCrLf & "Print Activation confirmation ?", vbOKOnly, "Processed"
strSQL = "UPDATE tbl_Activation SET tbl_Activation.Activated = strActivationResult WHERE id =1"
CurrentDb.Execute strSQL
DoCmd.Close , , acSaveYes
Else
MsgBox "Activation Unsuccessfull", vbExclamation, "Error"
Me.txtUnlockCode = ""
Me.txtUnlockCode.SetFocus
End If

End Sub

Table structure :

Fields: ID;Activated;UnlockCode

Id = number field (long number), set as primary key
Activated and UnlockCode fiels are text fileds
 

JANR

Registered User.
Local time
Today, 11:54
Joined
Jan 21, 2009
Messages
1,623
Since strActivationResults are string, you must enclose it with quotes.

Code:
SET tbl_Activation.Activated = [COLOR=red]'" &[/COLOR] strActivationResult [COLOR=red]& "'[/COLOR]

also you don't need to include the tablename in your set-statement since there isen't any ambiguety about which table to update.

JR
 

DCrake

Remembered
Local time
Today, 10:54
Joined
Jun 8, 2005
Messages
8,632
Thi sline is wrong

strSQL = "UPDATE tbl_Activation SET tbl_Activation.Activated = strActivationResult WHERE id =1"


it should read

Code:
strSQL = "UPDATE tbl_Activation SET Activated = '" & [COLOR="blue"]strActivationResult [/COLOR]& "' WHERE id =1"

However you have not passed a string or value to the variable strActivationResult
 

Mclaren

Registered User.
Local time
Today, 02:54
Joined
Mar 28, 2007
Messages
13
Thank you sooo much, i see my error with the strResult, i had my dim incorrect.

Works perfect.
 

DCrake

Remembered
Local time
Today, 10:54
Joined
Jun 8, 2005
Messages
8,632
Surprising what a fresh pair of eyes sees:eek:
Glad you got is sorted now:)
 

Users who are viewing this thread

Top Bottom