access-vba

Does VBA contain a comment block syntax? [duplicate]

余生长醉 提交于 2019-12-23 06:49:01
问题 This question already has answers here : How to comment and uncomment blocks of code in the Office VBA Editor (9 answers) Closed 3 years ago . In VBA is there a short way to comment out a block of code the same way java uses /*...*/ ? 回答1: Although there isn't a syntax, you can still get close by using the built-in block comment buttons: If you're not viewing the Edit toolbar already, right-click on the toolbar and enable the Edit toolbar: Then, select a block of code and hit the "Comment

How to lock specific rows in a subform when a form loads?

三世轮回 提交于 2019-12-23 05:50:47
问题 I have a subform containing records with a Yes/No field displayed as a checkbox on the subform. When the main form is loaded, I need to lock all checked fields so that the user cannot undo what a previous user did: they should only be able to check/uncheck the boxes that were unchecked at the start of thier session. Is it possible to iterate through all the records in a subform and lock the records selectively based on the field value when a form is loaded? I know I can put something like If

Access add new line to table

萝らか妹 提交于 2019-12-23 05:48:06
问题 I have sub that runs when the database is opened to a specific form and I'm trying to get it to add information in a table. The table name is UnAuthorizedAccess and the columns in table are ID(auto number), NAME(text), COMPUTERNAME(text), ATTEMPTDATE(date/time). What commands do I need to use to add a new record to this table? I have a VBA that if they're login information Isn't there is will force close access all together. I'm trying to gather information on the user as well before kicking

Microsoft Access - Show name of logged in user from UserID

瘦欲@ 提交于 2019-12-23 05:45:16
问题 I have an Access database I'm working on which has a simple login system consisting of a drop down (combo) menu to select the username, a password field and a users table. Inside the users table, I'm storing the username, password and the first name of all the users. I've managed to get my login form working, but I'd like the user's first name to be displayed in a text box on the next form. I've managed to get the user's ID number, and display it in a text box, but I haven't been able to get

Run time error 3021 - EOF or BOF is true or the current record has been deleted

你离开我真会死。 提交于 2019-12-23 05:09:30
问题 rst.Open "SELECT * FROM Equipas WHERE ([ID - Funcionário] LIKE '" & idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );", CurrentProject.Connection, adOpenDynamic, adLockOptimistic rst.Delete adAffectCurrent rst.Update rst.Close I receive the runtime error 3021 however the query is not empty. 回答1: "I receive the runtime error 3021 however the query is not empty." Double check that point. Dim strSelect As String strSelect = "SELECT * FROM Equipas " & _ "WHERE ([ID - Funcionário] LIKE '" &

ACCESS VBA - cannot create relations

非 Y 不嫁゛ 提交于 2019-12-23 05:09:21
问题 So take the following example: Sub CreateRelation() Dim db As Database Dim rel As Relation Dim fld As Field Set db = CurrentDb Set rel = db.CreateRelation("OrderID", "Orders", "Products") 'referential integrity rel.Attributes = dbRelationUpdateCascade 'specify the key in the referenced table Set fld = rel.CreateField("OrderID") fld.ForeignName = "OrderID" rel.Fields.Append fld db.Relations.Append rel End Sub I keep getting the error: No unique index found for the referenced field of the

How could I use VBA to change a button's picture to one of the embedded default images?

℡╲_俬逩灬. 提交于 2019-12-23 04:45:43
问题 I'm trying to get a button to change from the "Arrow Left" to "Arrow Right" picture when I click it, but I'm not sure how to assign the images through VBA. I tried Me!btnCollapseUnscheduled.Picture = "Arrow Left" , but I get an error message this way. 回答1: In Access 2010 or later, you can store images in the MSysResources system table. Then choose Shared for your command button's Picture Type property, and select one of those shared images. Afterward, it's easy to toggle between the shared

VBA Access get string from db

懵懂的女人 提交于 2019-12-23 03:25:33
问题 I have a table with a column contain email addresses. I would like to get these email addresses and send mail to them. My problem is that i don't know how to get the addresses. I would like to get a string as me@email.com;me2@email.com;me3@email.com...etc How can i get this string in order to pass it to the recipents? 回答1: From memory (not tested): Dim db As DAO.Database, rs As DAO.Recordset Dim s As String Set db = CurrentDb Set rs = db.OpenRecordset("SELECT email FROM myTable WHERE ...") Do

Inserting into SQL Server using MS Access

一笑奈何 提交于 2019-12-23 02:43:08
问题 I know this will be a common problem, nevertheless I didn't find any solution. I migrated my access database into SQL Server Express. SELECT and UPDATE work well, actually better that with the Access engine. But I can't get standard insertions running... This does not work: Set rc = CurrentDb.openRecordset("SELECT * FROM DBLog WHERE false") rc.AddNew rc.update '-->ERROR rc.close This does not work either: DoCmd.RunSQL("INSERT INTO [test2].dbo.DBLog (type) VALUES (6)") This does work: sending

Inserting into SQL Server using MS Access

。_饼干妹妹 提交于 2019-12-23 02:42:56
问题 I know this will be a common problem, nevertheless I didn't find any solution. I migrated my access database into SQL Server Express. SELECT and UPDATE work well, actually better that with the Access engine. But I can't get standard insertions running... This does not work: Set rc = CurrentDb.openRecordset("SELECT * FROM DBLog WHERE false") rc.AddNew rc.update '-->ERROR rc.close This does not work either: DoCmd.RunSQL("INSERT INTO [test2].dbo.DBLog (type) VALUES (6)") This does work: sending