473,387 Members | 1,540 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,387 software developers and data experts.

How to get else statement to function properly?

I apologize for my current lack of knowledge and hope that someone will be kind enough to give me some additional help.I posted a question regarding "Record does not exist, open add record form". I have managed (with the help of ADezii) to have the add new user form open up if there is no matching userID record in the TBLUser (BTW Userid is text) however even if the user does exist the add new user form opens up. I think I need an "Else" statement "telling" the DB that if the user exists, just go to the next field. Here is the code I have that seems to work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command118_Click()
  2.  
  3. 'Create var.Dim intChk As Integer
  4. 'This line counts the number of rec instances in TBLUser.    
  5. intChk = DCount("*", "TBLUser", "[UserID]" = "'" & Forms!FrmCreateNewLaptopProfileForBookings!UserID & "'")    
  6.  
  7. 'Does the rec exist? If not then open FRMCreateNewUserWhileBooking to add the new user details.    
  8. If intChk = 0 Then 'No?        
  9. DoCmd.OpenForm "FRMCreateNewUserWhileBooking", , , , acFormAdd               
  10.  
  11. End If
  12.  
  13. End Sub
I think the Else statement should be something like:

Expand|Select|Wrap|Line Numbers
  1. Else    
  2. If intChk > 0 Then    
  3. SetFocus Me!Barcode
  4.  
But I can't get it to work.

Many Many thanks for your help and patience with a newbie!!Robert
Feb 1 '11 #1
2 1469
TheSmileyCoder
2,322 Expert Mod 2GB
I would suggest reading :
Debugging VBA
Used correctly you can save loads of time, by knowing how to properly debug.

Your If statement is fine, if you find that it is firing even though the user exists, it MUST mean that intChk is 0. That must mean that you have a syntax error in your statement:
Expand|Select|Wrap|Line Numbers
  1. intChk = DCount("*", "TBLUser", "[UserID]" = "'" & Forms!FrmCreateNewLaptopProfileForBookings!UserID & "'") 
And Please Please Please use [code]...[/code]tags around your code when posting.
Feb 1 '11 #2
dsatino
393 256MB
TheSmileyOne is correct. Your intChk variable must be 0. Try this.

Expand|Select|Wrap|Line Numbers
  1. intChk = DCount("*", "TBLUser", "[UserID] = '" & Forms!FrmCreateNewLaptopProfileForBookings!UserID & "'")  
  2.  
Feb 2 '11 #3

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

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
33
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but...
2
by: William.Joseph.Batson | last post by:
Hi, I found the following c++ code, but I need help in understand what it is trying to do: if the caller does this DPRINTF(D_MINI_FS, ("CHXMiniFileSystem()\n")); what will happen according...
1
by: darrel | last post by:
Hi vb master i need help on this here my code: If Combo1(0) = rs.Fields("TimeStart") And Combo4(0) = rs.Fields("TimeEnd") And Combo2(0) = rs.Fields("ROOM") And Combo3(0) = rs.Fields("DAYS")...
8
by: MLZ242 | last post by:
I'm supposed to write a program that is going to calculate absolute value of given number(and print appropriate message) but I'm having tough time with the statements(expected primary-expression...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
3
by: sigkill9 | last post by:
I've been working on this script all weekend and am almost done with it accept for one last detail; implementing a "process another number?" prompt after a user input is processed. The script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.