Adding a recored using VB CODE ONLY?

mr_e_landis

Registered User.
Local time
Today, 15:08
Joined
Feb 16, 2005
Messages
28
I have a form that changes a part number. When a user changes the part number and clicks on save a yesno dialog pops up tells them what has been changed and askes the user if they want to document what the prior part number was. I have a table that contains 3 feilds, the key, partnumber, and priorpartnumber. I want to open and add a new record to this table based on the info that is on the form. Can I do this in the code and if so can someone give a good example or link to a good example?
Thanks for the help.
 
Something like this...

Private Sub Macro_Button_Click()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString

DoCmd.SetWarnings False

Msg = "Document Prior Part Number?" ' Define message.
Style = vbYesNoCancel ' Define buttons.
Title = "Change Part Number" ' Define title.
Help = "" ' Define Help file.
Ctxt = 0 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.

Update_Table 'Procedure to insert into table from form

End If

End Sub



Function Update_Table

Dim dbs As Database
Dim strSQL, FIELD1, FIELD2, FIELD3 As String

DoCmd.SetWarnings False

FIELD1 = Forms![FORMNAME]![FIELDNAME]
FIELD2 = Forms![FORMNAME]![FIELDNAME]
FIELD3 = Forms![FORMNAME]![FIELDNAME]

Set dbs = CurrentDb

StrSQL = "INSERT INTO TABLE VALUES ('" & FIELD1 & "', '" & FIELD3 & "' " & FIELD3 & "');"

DoCmd.RunSQL (strSQL)

End Function
 

Users who are viewing this thread

Back
Top Bottom