ms access - Updating table with VBA -
I am struggling to work this code for a few days. If you can offer any solutions, then I really appreciate it.
Private subcommands0_Click () If IsNull (NewSupBox.Value) or IsNull (NewNumberBox.Value) then MsgBox ("All fields must be filled") Goto ErrorExit end then not IsNull (DLookup (if "SupplierNumber", "SupGenInfo.SupplierNumber =" & NewSupBox)) = Then the MsgBox ("This supplier number already exists. You can edit the existing record on the editors page.") Goto ErrorExit end Then set the dim db database def REC record set db = CurrentDb set as REC = db.OpenRecordset ("Select * SupGenInfo Scope ") rec.AddNew rec (" SupplierNumber ") = Me.NewSupBox.Value rec (" SupplierName ") = Me.NewNameBox. Value rick UPDATE set REC = nothing set DB = some message box "Record successfully added." Error: Max: End all Edit: I forgot to mention that I do not find an error message. This command will not only add a new record to my table.
Edit 2: "Records added successfully" on the above code msg will be when I remove the following block of code.
dd.DD. OpenDb set set rec.AddNew Rec ("SupplierNumber") = Me.NewSupBox (REC As "SupplierName") = Me.NewNameBox rec.Update set rec = None set DB = nothing This happens when this code is included in my order The click becomes unresponsive
I believe, you are displaying a table with your select * (For display purposes). .. statement, then you are adding a new record to that list instead of the actual database. When you open OpenRecordset , just supply the table name, not the whole SQL query Shebang ... I have created a new table, so your parameters / values Edit this code to match
Dim database database set the rec record set set db = CurrentDb set REC = db.OpenRecordset ("Table1") as rec.AddNew rec ("Field 1":, otherwise it has been tested to work) = 1234 RE ("Field" D2 ") =" blah2 "RE (" field 3 ") =" blah3 "rec.Update set REC = nothing set db = nothing Hope this helps.
Comments
Post a Comment