473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple If Statements with multiple Cmd's

Brilstern
208 100+
I am having trouble getting a full understanding of how to use multiple if statements. I want to first use the msgbox, and if vb yes then import the two spreadsheets below with if statements here checking first if a file is present, is so then import them, if not import the blank file for both imports. Not really sure how to word this correctly but I and getting a compile error, Block If without End If.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command27_Click()
  2.  
  3. If MsgBox("Are you sure you want to import today's JRC Manifest?", vbYesNo, "Importing") = vbYes Then
  4.     If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Inbound\In.xlxs") = "" Then
  5.         DoCmd.RunSavedImportExport "Import-In"
  6.       Else
  7.         DoCmd.RunSavedImportExport "Import-Inblk"
  8.         If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Outbound\Out.xlxs") = "" Then
  9.           Else
  10.             DoCmd.RunSavedImportExport "Import-Outblk"
  11.             DoCmd.Requery ""
  12.  
  13. End If
  14.  
  15. End Sub
Dec 22 '11 #1

✓ answered by TheSmileyCoder

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command27_Click()
  2. 'Get confirmation from user
  3.   If vbYes=MsgBox("Are you sure you want to import today's JRC Manifest?", vbYesNo, "Importing") Then
  4.     'Check for file existance Inbound
  5.       If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Inbound\In.xlxs") = "" Then
  6.           'File does not exist, import blank sheet      
  7.           DoCmd.RunSavedImportExport "Import-In"
  8.         Else
  9.           'File exists, import
  10.           DoCmd.RunSavedImportExport "Import-Inblk"
  11.       End If
  12.  
  13.  
  14.     'Check for file existance outbound
  15.       If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Outbound\Out.xlxs") = "" Then
  16.           'File does not exist, do nothing
  17.         Else
  18.           'File exists
  19.           DoCmd.RunSavedImportExport "Import-Outblk"
  20.        End If
  21.  
  22.    'Done importing, update screen
  23.      DoCmd.Requery ""
  24.   End If
  25.  
  26. End Sub

4 1708
TheSmileyCoder
2,322 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command27_Click()
  2. 'Get confirmation from user
  3.   If vbYes=MsgBox("Are you sure you want to import today's JRC Manifest?", vbYesNo, "Importing") Then
  4.     'Check for file existance Inbound
  5.       If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Inbound\In.xlxs") = "" Then
  6.           'File does not exist, import blank sheet      
  7.           DoCmd.RunSavedImportExport "Import-In"
  8.         Else
  9.           'File exists, import
  10.           DoCmd.RunSavedImportExport "Import-Inblk"
  11.       End If
  12.  
  13.  
  14.     'Check for file existance outbound
  15.       If Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Outbound\Out.xlxs") = "" Then
  16.           'File does not exist, do nothing
  17.         Else
  18.           'File exists
  19.           DoCmd.RunSavedImportExport "Import-Outblk"
  20.        End If
  21.  
  22.    'Done importing, update screen
  23.      DoCmd.Requery ""
  24.   End If
  25.  
  26. End Sub
Dec 22 '11 #2
Brilstern
208 100+
I had to change a few things but I understand it a little bit better now. I am sorry on my lack of code logic, I a have only really built two databases for work in the military and it is nowhere in my normal job field. I appreciate the quick reply everything works now. Not used to posting code as well. I had to google code tags...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command27_Click()
  2.     'Get confirmation from user
  3.       If vbYes = MsgBox("Are you sure you want to import today's JRC Manifest?", vbYesNo, "Importing") Then
  4.         'Check for file existance Inbound
  5.           If Len(Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Inbound\In.xlsx")) = "0" Then
  6.              'File does not exist, import blank sheet
  7.               DoCmd.RunSavedImportExport "Import-Inblk"
  8.             Else
  9.               'File exists, import
  10.               DoCmd.RunSavedImportExport "Import-In"
  11.  
  12.           End If
  13.  
  14.  
  15.         'Check for file existance outbound
  16.           If Len(Dir("\\lnknfs01\share\rcsw\c-1\0-II MEF (FWD) (1 MAR 2011)\0-Manpower Section\JRC Manifest\Outbound\Out.xlsx")) = "0" Then
  17.               'File does not exist, import blank sheet
  18.               DoCmd.RunSavedImportExport "Import-Outblk"
  19.             Else
  20.               'File exists, import
  21.               DoCmd.RunSavedImportExport "Import-Out"
  22.            End If
  23.  
  24.        'Done importing, update screen
  25.          DoCmd.Requery ""
  26.       End If
  27.  
  28.     End Sub
Dec 22 '11 #3
NeoPa
32,556 Expert Mod 16PB
Stevan Bias:
Not used to posting code as well. I had to google code tags...
Well, that sets you apart from most members then :-) Most just ignore them. You've done a good job even without any prior understanding.

As a tip for a new user who obviously has the intelligence and attitude to get things done, check out Context-Sensitive Help. You will find so much to help you get going, even with things you've not come across before in VBA.
Dec 22 '11 #4
Brilstern
208 100+
NeoPa,

I appreciate the Tip. I will definitely utilize that. I have a lot to learn in Access and any help Is depreciated.
Dec 22 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Shmuel | last post by:
Is it possible to query multiple statements at once? Like: $query = "set @p := 1; select @p + 1"; $results = mysql_query($query); I'm thinking of PHP4. There is in mysqli the prepare...
2
by: Richard Adams | last post by:
Is it possible to execute more than one statement in SQL via MDAC ODBC? I have a fairly complex select I wanted to create a view with, but trying to send it all as one string with terminators ';'...
1
by: Erik Haugen | last post by:
This item in the C++ faq: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.5 discusses macros with multiple statements. The problem is that a macro such as #define...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Nabil | last post by:
I am new to DB2 and here is my situation. I have 2 temp tables where I am trying to insert data (from 2 select statements) DECLARE v_t1 VARCHAR(50); DECLARE v_t1 VARCHAR(50); DECLARE stmt1...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
7
by: paladin.rithe | last post by:
I have 2 statements that I'd like to string together in a query, but according to everything I'm seeing, it's not possible. What I'm doing is an insert of a row, where the primary key is an auto...
6
by: jodleren | last post by:
another topic though related to the previous post. How do IF behave in php? Say, if( $goahead && copy($somefile1, $somefile2) ) echo "hello world"; What if $goahead is false, will the if...
0
by: harsha318 | last post by:
Hi I need to have a single query and which can have multiple statements For eg: string str = string.Empty; str = "select * from Customers;Select * from Orders"; iDB2Connection iDB2con =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.