0% found this document useful (0 votes)
100 views3 pages

All Vba Access

This document provides code snippets for common VBA tasks in Microsoft Access including opening and closing forms, running queries to create, read, update and delete records, opening reports, filtering records on forms, displaying message boxes, looping through recordsets, and basic error handling.

Uploaded by

dg.yasminaclick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views3 pages

All Vba Access

This document provides code snippets for common VBA tasks in Microsoft Access including opening and closing forms, running queries to create, read, update and delete records, opening reports, filtering records on forms, displaying message boxes, looping through recordsets, and basic error handling.

Uploaded by

dg.yasminaclick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

{

"data": [

"Open a Form",

"DoCmd.OpenForm \"FormName\""

],

"Close a Form",

"DoCmd.Close acForm, \"FormName\""

],

"Navigate to a Specific Record on a Form",

"DoCmd.GoToRecord acDataForm, \"FormName\", acGoTo, RecordNumber"

],

"Run a Query (Create)",

"DoCmd.RunSQL \"INSERT INTO TableName (Field1, Field2) VALUES ('Value1', 'Value2')\""

],

"Run a Query (Read)",

"Dim rs As Recordset\nSet rs = CurrentDb().OpenRecordset(\"SELECT * FROM TableName WHERE


FieldName = 'Value'\")\nMsgBox rs!FieldName"

],

"Run a Query (Update)",

"DoCmd.RunSQL \"UPDATE TableName SET FieldName = 'NewValue' WHERE Condi�onField =


'Value'\""

],

"Run a Query (Delete)",

"DoCmd.RunSQL \"DELETE FROM TableName WHERE FieldName = 'Value'\""

],
[

"Open a Report",

"DoCmd.OpenReport \"ReportName\", acViewPreview"

],

"Filter Records on a Form",

"Me.Filter = \"[FieldName] = 'Value'\"\nMe.FilterOn = True"

],

"Message Box",

"MsgBox \"Your message here.\", vbInforma�on, \"Title\""

],

"Confirm Ac�on with a Message Box",

"Dim response As Integer\nresponse = MsgBox(\"Are you sure?\", vbYesNo, \"Confirm\")\nIf


response = vbYes Then\n ' Code to execute if Yes is clicked\nEnd If"

],

"Open an External Database",

"Dim db As Database\nSet db = OpenDatabase(\"C:\\Path\\To\\Database.accdb\")"

],

"Loop Through Records in a Recordset",

"Dim db As Database\nDim rs As Recordset\nSet db = CurrentDb()\nSet rs =


db.OpenRecordset(\"SELECT * FROM TableName\")\n\nDo While Not rs.EOF\n ' Your code here. For
example:\n MsgBox rs!FieldName\n rs.MoveNext\nLoop"

],

"Error Handling",

"On Error GoTo ErrorHandler\n' Your code here\n\nExit Sub\n\nErrorHandler:\nMsgBox \"An


error occurred: \" & Err.Descrip�on"

]
]

You might also like