So i want to be able to make the whole syntax available for user to edit without actually doing it in vba. is this possible in vba? i have attached an image
What is the best way to handle a complex conditonal statement like this? I thought about nested statements but i'm not sure if i can put all of these statements in the expression. There are some other conditions that i did not include.
If VBand = A and if CBand = A, allowed If VBand = B and if CBand = B, allowed If VBand = A and if CBand = A/B, allowed If VBand = B and if CBand = A/B, allowed If VBand = A and if CBand = A/C, allowed If VBand = B and if CBand = B/C, allowed If VBand = A and if CBand = A/C, allowed
If VBand = B and if CBand = C, not allowed If VBand = B and if CBand = C, not allowed except certain areas If VBand = A and if CBand = C, not allowed If VBand = C and if CBand = A, not allowed except certain areas If VBand = C and if CBand = C, not allowed If VBand = A and if CBand = B, not allowed except certain areas If VBand = C and if CBand = B, not allowed except certain areas If VBand = A and if CBand = B/C, not allowed If VBand = B and if CBand = A/C, not allowed If VBand = C and if CBand = A/C, not allowed If VBand = C and if CBand = A/B, not allowed If VBand = C and if CBand = A/B/C, not allowed If VBand = C and if CBand = B/C, not allowed except certain area
I am creating a report based off a query. My problem is that I am trying to create conditional statements within a unbounded text box. I would like to say: =[Field] where [Field2] = X. Unfortunately, I can not find any support on this matter.
I am writing some iif conditional statements in one of my tables to assign new values in that table.
Code: FP: IIf([cohort with status].[Intake Date] Between #04/01/2012# And #26/04/2012#,201201) Or IIf([cohort with status].[Intake Date] Between #27/04/2012# And #24/05/2012#,201202)
When I run it, I am getting some -1 values in the new column FP.
but if I get rid of the second IIF, then it works.
how do you combine multiple IIF statements in a query?
I can't make edits with ADODB recordset bound to my form.
Access 2010 linking to SQL Server 2008.
Simple form bound to a single table.
Connection string works fine.
Code is as below (cursor etc is set using enums btw).
Private Sub Form_Open(Cancel As Integer) Dim rst As ADODB.Recordset If g1OpenRecordset(rst, "tblName", rrOpenKeyset, rrLockOptimistic, False) = False Then Cancel = True Exit Sub
I created a form that applies conditional formats depending on a field. It works fine, until you enter data into one of the conditionally formatted fields, then all hell breaks loose. Conditional formats totally go away and the cells go to #error.
What I am trying to do is create conditional formatting to colour fields within a form.
The conditional formatting option built in allows me to colour based on set values i.e. Value=Design turns green. I need to somehow say if Value contains the word Design turn green. This is because in addition to the word Design there will be a variable description. I tried editing the conditional format created by the wizard to Value="*Design*" but that didn't work.
Now I'm trying to write it in VBA code but am still struggling. Here's what I tried but it doesn't like it:
If InStr([Forms]![Query2]![Activity] Like "*Design")>0 Then [Forms]![Query2]![Activity].BackColor = vbGreen End If
Basically I want to check if the Reporting Month already exists in the Months Table. If it exists it should ask the User wheter to overwrite or not. If the User clicks on OK it should delete one record from Months Table if the User clicks no, nothing should happen.However it doesn't delete the record, when I click on OK.
Code:
Public Sub IMPORT_Click() Dim filelocation As Variant Dim f As Object Dim Message As String, Title As String, Default As String Dim sql As String Dim MsgReply As Integer
The following SQL statements run with no errors, but I can't see the output of the SQL statements. What is wrong with my "Debug.Print" or "rs" statement ? I would like to see the results. The SQL statements works when I save them to a query.
Dim db As DAO.Database Dim rs As DAO.Recordset Rem Dim intResult As Integer Dim strSQL As String Set db = CurrentDb
I've seen a common solution is to double up the apostrophe, replacing ' with " to avoid the special character however i also hear of another solution using "parameters".I tried have a look around on the internet and got confused so I thought maybe it would be better to ask here.
I just want to change my INSERT INTO and UPDATE commands to be able to use this (to prevent a potential sql injection) also i think its important to know im using DOA to code? (not sure if its important) either way.
I'm trying to put multiple IF statements into one procedure like the below:
Dim Answer As Integer Answer = MsgBox("Have You Selected The Correct Outcome?", vbCritical + vbYesNo, "Continue Request?") If Answer = vbYes Then 'Works fine here 'The bit I can't get right
How do you write complex nested IF THEN ELSE END IF statements..How do you know what IF statement to put first?Then how would you know where to put ELSE, or END IF?Before you start with the VBA, what are the foundations for making it work successfully, know where you are, know where to put END IF etc?
I've seen many times when using VBA people set up an initial foundation for writing code. For example when needing to put something in quotes, they do "" then enter the text in between, so they don't get errors on running (A very simple, crude example I know, but is there a similar basis for nested IFs).
I have coded a select statement that uses multiple tables for information used to populate a report. It returns the correct information, sort of, but it doesn't recognize the already existing table relationships so I get dupicate records. Is there a way to run the code so that it recognizes the table relationships?
I'm having problems with quotation marks in a sql statement. The string is an array separated by a semicolon.
120/80;70;5'6";125
this string represents patient vitals. I'm using the string to update a record. But I get hung up with the quotation mark.
I've tried: 120/80;70;5''6'"';125 which is a enclosing the quotation mark with apostrophies, but this does not seem to work. The sql still gets hung up. My sql statment looks something like:
original string: 120/80;70;5'6";125
strPreOpVits = "120/80;70;5''6'"';125"
mysql = "UPDATE mytable SET PreOpVits = '" & strPreOpVits & "' " & _ "WHERE nID = " & myRecID
docmd.runsql mysql
I've narrowed it down to the quotation marks and I'm unsure how to handle these. I get a runtime 3075 - Syntax Error.
Here is the code that I use to convert the original string
Public Function FixQuotesInSql(strToFix As String) Dim lgth, y As Long Dim strTemp, char2Add As Variant 'This routine fixes the use of apostrophe and quotation marks in an SQL sequence 'If the apostrophe is at the beginning or end of the string it replaces with 3 x "'" or "'''" 'If in the middle of the string then replaces with 2 x "'" or "''"
I created a database for obtaining customer information at a trade show. The entry form is set to Pop up. Entry in data fields is required. I set a macro at the end of the entry form, "New Record Macro" to save the record and then to GoToRecord to create a new blank form for the next person to fill in. When a field is left blank, an error screen pops up using the actual name of the field left blank. Then a Macro Single Step error screen pops up. I need to replace these pop ups with customized directions. I'd like to completely eliminate the Macro Single Step error. I have no experience in Visual Basic. I am using Access 2010.
For some reason i've had to make an update on some old VBA projects of mine. In this update i switch all references of DAO to ADO. I know there are some limits to what i can accomplish with ADO (where i would need to use DAO). Anyways in some of these old projects i use an SQL statement to provide me with a limited number of records which i then modify by iterating through the recordset.
I can't get this to work with ADO. It's as if it always expects me to provide a table in the argument.
In short my question is. Is it possible to change the values returned from an SQL statement using ADO
Code: 'This is the DAO version which is exactly what i'm looking to using ADO strSqlCommandText = "SELECT tblMain.TaskID, tblMain.Heading FROM tblMain WHERE (((tblMain.TaskID)=" & ProcessForm.txtIDValue.Text & "))" Set objRecordset = pubObjDatabase.OpenRecordset(strSqlCommandText, dbOpenDynaset) objRecordset.Edit objRcsToDbTable.Fields("Heading") = ProcessForm.txtBoxHeading.Text objRecordset.Update
This is what i've done and it doesn't work.
Code: strSqlCommandText = "SELECT tblMain.TaskID, tblMain.Heading FROM tblMain WHERE (((tblMain.TaskID)=" & ProcessForm.txtIDValue.Text & "))" Set objRecordset = New ADODB.Recordset objRecordset.Open strSqlCommandText, pubObjDatabase, adOpenDynamic, adLockOptimistic objRecordset.Edit objRcsToDbTable.Fields("Heading") = ProcessForm.txtBoxHeading.Text objRecordset.Update
I can think of some work around like, creating a temp table and insert/update all the records from there or creating an UPDATE SQL statement.
I have an edit button in my form which activates VBA, collects all data from the fields and edit the dataset. Everything work fine except the case that next to the edit access adds a new record as well with exactly the same data.
This is my code :
Dim db As Database Dim rs As Recordset Set db = CurrentDb Set rs = db.OpenRecordset("select * from tbllocations where locationid = " & cdkey)
[code]...
I checked every parameter and it seems everything is OK which surely is the base for the correct edit of the dataset. locationid is the key of the table.
I have a report that I run which has PT_Ins_ID in it, I am trying to edit that row with the following code.
Code: Private Sub cmd_Deact_Click() Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("dbo_Patient_Insurance") If rs.RecordCount <> 0 Then With rs
[code]....
I've also tried this.
Code: Dim rs_PI As DAO.Recordset Set rs_PI = CurrentDb.OpenRecordset("dbo_Patient_Insurance")
Within my table 'Contacts' I have the field 'City' which as you would expect contains the city.
The data in the City field which is sourced from the web can often merge two regional municipalities into 1 and I know through digging in behind the data what the correct answer should be.
I am looking to accomplish a list of edit replaces that takes 30 + edits and automates.
Change "ClevelandAkron" to "Cleveland" Change "Dublin 2" to "Dublin" Change "Greensboro/Winston-Salem" to "Greensboro" etc. etc.
There are 10,000 plus entries in the table of which many are correct.
I'm currently using the following to edit a publisher document using access VBA.
Code: For Each pubShape In pubDoc.Pages(1).Shapes If pubShape.HasTextFrame Then If pubShape.Name = "Text Box 440" Then pubShape.TextFrame.TextRange.Text = Item1 If pubShape.Name = "Text Box 441" Then pubShape.TextFrame.TextRange.Text = Item2 If pubShape.Name = "Text Box 442" Then pubShape.TextFrame.TextRange.Text = Item3 If pubShape.Name = "Text Box 443" Then pubShape.TextFrame.TextRange.Text = Item4 If pubShape.Name = "Text Box 444" Then pubShape.TextFrame.TextRange.Text = Item5 If pubShape.Name = "Text Box 445" Then pubShape.TextFrame.TextRange.Text = Item6 If pubShape.Name = "Text Box 446" Then pubShape.TextFrame.TextRange.Text = Item7 If pubShape.Name = "Text Box 447" Then pubShape.TextFrame.TextRange.Text = Item8 End If Next
Obviously there are a lot of shapes/boxes etc in the document and this code is very inefficient and takes a few moments to complete. Is there a way to directly reference a text box and change its value. For word I have been using bookmarks but this doesn't seem to work with publisher.
I'm looking for something like pubshape.Value("text Box 440") = Item1 but cannot find the correct syntax.
I have two table. Table 1 (assets) list all my assets etc. Table 2 lists all servicing for each asset.
I have a form which generates a list box of items that require servicing (once servicing has been completed on these items) I would like to update all records, in both tables. Table 2 with all the information about the service. and Table 1 with (only) the next service date.
I have set the list box to allow multiple selection and have used the following code to allow new records to be update in table 2 (which works). but I cant seem to get the code to edit one cell in table 1.
private Sub Command59_Click() Dim strSQL As String Dim db As DAO.Database
While the form itself is bound to tbl_Orders I decided to use unbound text boxes to enter the data (knowing I was in for some work!). Reason is that if textboxes were bound would need to use a subform with multiple combo boxes and that UI did not seem suitable for the application.
I’ve completed the code to add new records to tbl_Orders and tbl_Junction from the unbound textboxes. I'm using the VBA .AddNew method and is working well. Now I need to integrate code that will allow users to edit existing records while they are viewing them on the form.
I have the code to look up the record set I want to edit in tbl_Junction and am familiar with the .Edit method but the issue is that the required changes MAY include not just editing existing records but also deleting and adding new records. For example, the initial order may have been for Apples and Oranges and the revised order may change the number of Apples, eliminate Oranges entirely, and add some Bananas. So, it seems I need to .Edit Apples, .Delete Oranges, and .AddNew Bananas?
Should I try to write code to determine where I need to .Edit/.AddNew/.Delete? -- not looking forward to that. Thought maybe could delete the entire junction record set and then just .AddNew for everything per the revised order. That should work as the display on the form would be correct for the whole order. But maybe would cause a problem as would remove the FK in tbl_Junction that corresponds to the PK in tbl_Orders?
I am attempting to adjust the font color of a date field on a report based on the value of two other fields. I have the below code set in the "On Format" property of my detail section - however it does not work when I open the report to view.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) If Me.Frequency = "Annually" Then If Me.ClassDate < (DateAdd("yyyy", -1, Date)) Then Me.ClassDate.ForeColor = vbRed Me.ClassDate.FontBold End If End If End Sub
I'm trying to write a line of VBA code (in an existing Access 2010 DB) that changes the Subject Line of all selected emails in my Outlook Inbox to today's date.