if-then statement in vba

I have a form called restaurantinfo with a save button on it, and some simple vba behind it. A text box called savedtext appears when it is clicked to show the user that their info has been saved:

Private Sub savebutton_Click()
DoCmd.Save
Me.savedtext.Visible = True
End Sub

How can I make an (if-then) statement that says that if any further changes are made to the info (pulling from table restaurantinfo) on the form, then Me.savedtext.Visible = False ?

Sponsored Links:

Related Topics

Copy SQL statement from query to VBA
Rather than typing complex query statements into VBA code, developers often mock up a query graphically, switch it to SQL View, copy, and paste into VBA.
If you've done it, you know how messy it is sorting out the quotes, and the line endings.
Learn how to build a form that massages the SQL statement from a query, so it can be pasted into a VBA procedure in Microsoft Access.


Case Statement
In Access, the Case statement can only be used in VBA code. It has the functionality of an IF-THEN-ELSE statement.


IF-THEN-ELSE Statement
In Access, the IF-THEN-ELSE statement can only be used in VBA code.


Use a SQL statement to delete data
Writing SQL to delete data from an MS Access table is just about the easiest SQL statement you can write.
This example will use the SQL statement to create an Access query, but you can use the statement in a macro or VBA as well.


Which is better? checking in VBA or SQL
I currently have a VBA statement that runs SQL to append to a table. I want to first check if there is already a record with the same name in the table to avoid duplicate entries.

Is it best to check before the query is run in the VBA, or in the SQL statement it's self to avoid this problem better?

I'm not sure how I even would check the table with SQL.


if-then statement in vba
I have a form called restaurantinfo with a save button on it, and some simple vba behind it. A text box called savedtext appears when it is clicked to show the user that their info has been saved:

[CODE]

How can I make an (if-then) statement that says that if any further changes are made to the info (pulling from table restaurantinfo) on the form, then Me.savedtext.Visible = False?


How would I write a Before UpdateIf Statement
I need VBA help with an If statement in the before update that would check if txtTitle, txtVWI, cboDepartment, cboVWICategory, cboApprover had data and if so it would set focus to the subform (frmVWISubform) text box (txtStepNumber) and if not then it cancel and exit sub.


Msg Dialog Box Prompt
Request some assistance,

I created a button with the following vba action statement

Private Sub Refreshtxttrig_Click()
DoCmd.RunSQL "drop table [Table Name]"
Exit_CmdImportExcel_Click:
End Sub

(This statement deletes a specific table within access.)

It works well, except when the Table is missing or I accidently click twice, it executes the statement but brings up a "runtime error." instead.

I would like to create a statement that will bring up a MsgBox instead of a runtime error and tells the user that the Table has already been purged


Use a control in an SQL statement in Access
In Access 2003/XP/2000/97, I've created a form where the user enters a value in a textbox. I want to use this value to create an SQL statement. How do I use a control's value in an SQL statement in VBA code?


TransferText VBA Import Issue
I'm trying to a VBA docmd.TransferText statement (properly formatted) to import and append "csv" data to an existing table, e.g.

PHP Code:
DoCmd.TransferTextacImportDelim,"ImportSpecification","tbImportedData",strPathAndFile,vbNo

The VBA code creates a new table with an identical name, while a manual import properly appends the existing table.

Can VBA be used to append an existing table with a TransferText statement


Two VBA Problems
Trying to do a couple quick things. I'm working in a software that interfaces with Access.

First problem:

Somehow this results in an infinite loop. But, I have printed the counter instead of the message and it reads 1.

Second problem:

This is actually going to fit in the first part at some point. But, the main issue is that the second eval(temp) statement is not working. I don't understand why because I use it the first time and the .test1 = 1 statement shows up fine, so I know it is entering the if statement being tested as a string.


Test File Extension
Just joined and looking forward to hearing from everyone.!
Here's my first Access VBA question:

I have three types of files under certain directories ie. *.log, *.csv and *.txt
Hopefully, while inside an If statement, I'd like to test the extension of the files it has encountered.Then, after the test is satisfied, I would like the code to exit the if statement and go to another public function to import the file extension it has found.
I'm just learning vba, so


Convert Rowsource SQL to VBA
I am trying to convert an sql statement on the rowsource of a combo box to vba. The following is the part of my sql statement that I cannot figure out:

WHERE (((TB_LS_Bld.Dept)=[Forms]![Form1]![Combo12] Or (TB_LS_Bld.Dept)=[Table1]![Dept]));


Delete last character in field based on criteria
I've done some vb.net programming but am new to vba. I hate to ask to be spoon fed a solution, but I am under a time constraint. I essentially want to delete the last character in a field only if that last character is an "M", "T" or an "R". Would putting this statement

Left([fieldName], Len([fieldName]) -1)

inside a loop and conditional statement essentially do it? I am unsure of the vba syntax though.


Possible to use this in VBA
Is it possible to use a statement like this in VBA coding?

'Declaring Name here Dim Name(10) As String 'Code using to call Name and it is throwing a debug error on the Name(i) = Name(i+1) j = I
I = 0
If j > 10 Then j = 10 While I <= j If I < 19 Then FName(i) = FName(i + 1) End If
End If
I = I + 1 End

Debug error says.line saying subscript is out of range? Which is what makes me question is it possible to do this in VBA, I know you can in C# and other languages, thought i'd give it a whirl in VBA


between date to date in vba(syntax)
couple of quick questions.(same project as last time to those who helped) all going great, trying to sort the (now working) results a little more, first was by job number, now needs to be by job number and a DATE RANGE.

was originally filtering my recordset (successfully) with this (the debug.print return from the vba statement):

JobNumber Like '001*'

trying to work this into it:

JobNumber Like '001*' And ActivityDate = Between '#1/01/2000#' And '#06/30/2010#'

but not too sure on the syntax with the between statement in vba (its clear enough in the UI)

we're on a European date system (day/month/year) and use that in the UI, i've read I need to use (month/day/year) in vba, am doing so (let me know if I'm wrong there).
the above included date range gives me a missing operator error, i've tried a few variations on the way. I assume that having multiple filters in the .filter property of a recordset is


tryparse method
I am trying to use the tryparse method in some VBA code but apparently I am not using the correct syntax.

datatype.tryparse(text, variable) ?

Compile error:
Expected: line number or label or statement or end of statement

I've used this in VB but never with access.


Using an IN statement in VBA
I'm trying to replace a cumbersome multiple OR statement with an IN statement, but it is erroring out (in A2K).

Instead of this code:

If str = "A" OR str = "B" OR str = "C" OR str = "AB" OR str = "BC" Then 'do stuff End If

I'd like to use this code:

IF str IN ("A", "B", "C", "AB, "AC") Then 'do stuff' End If

The IN statement gives me a Compile Error 'Expected: Then or GoTo'. Can someone tell me what is wrong with my IN statement?


reference a field
how do I reference a field in VBA to compare values in an if statement, please help me with the []'s and ,'s and whatnot.

my statement should read like:

private sub after update
if {textbox on form} {is = to or matches text} {field on a query or table} then


The SQL Select Statement
Microsoft Access is a Visual Basic based application that allows the SQL statements to be embedded in VBA code and macros. One of the most used SQL statements, the SELECT statement, provides the much needed flexibility in the retrieval of data from a database.