473,493 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What's wrong with my VB code?

22 New Member
Hi, I'm working on an Access 2007 database. I'm trying to build a search form that opens up your search on a query. I was working before, but I feel like i change something and now, it doesn't give me what I'm asking for. I have three fields on the form (companycell, companyflux, companyribbon). I don't know how to incorporate the value from companycell to the field on the query.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Findbtm_Click()
  2.  
  3. If Me.CompanyCell.Value = "" Then
  4. Beep
  5.     Select Case MsgBox("Cell Company is required", vbOK)
  6.     Case vbOK: 'do nothing
  7.     Case Else: 'do nothing
  8.     End Select
  9. Else
  10.  
  11.     If [Companyflux] = [company name] Or [CompanyRibbon] = [Company] Or [Companyflux] = "" Or [CompanyRibbon] = "" Then
  12.  
  13.             DoCmd.OpenQuery "Sales"
  14.     Else
  15.      Beep
  16.         Select Case MsgBox("Combination not found. Would you like possible combinations?", vbYesNo)
  17.             Case vbYes: 'finds possible combinations
  18.                  Beep
  19.                  Select Case MsgBox("Would you like to make Flux unknown?", vbYesNo)
  20.                       Case vbYes: 'Makes flux company unknown
  21.                           Me.Companyflux.Value = ""
  22.                           Me.newflux = Me.Companyflux
  23.                           Me.newcell = Me.CompanyCell
  24.                       Case vbNo: 'leaves flux company as it is
  25.                           Me.newflux = Me.Companyflux
  26.                           Me.newcell = Me.CompanyCell
  27.                       Case Else: 'default case to trap any errors
  28.                                  'do nothing
  29.                  End Select
  30.                 Beep
  31.                 Select Case MsgBox("Would you like to make Ribbon unknown?", vbYesNo)
  32.                       Case vbYes: 'makes ribbon company unknown
  33.                           Me.CompanyRibbon.Value = ""
  34.                           Me.newribbon = Me.CompanyRibbon
  35.                           Me.newcell = Me.CompanyCell
  36.                       Case vbNo: 'leaves ribbon company as it is
  37.                           Me.newribbon = Me.CompanyRibbon
  38.                           Me.newcell = Me.CompanyCell
  39.                       Case Else: 'defaul case to trab any errors
  40.                                   'do nothing
  41.                 End Select
  42.                 If [newflux] = [company name] Or [newribbon] = [Company] Or [newflux] = "" Or [newribbon] = "" Then
  43.  
  44.                  DoCmd.OpenQuery "Sales", acViewNormal
  45.  
  46.                 Else
  47.                  Beep
  48.                    Select Case MsgBox("Combination not found. Would you like to add a New Product?", vbYesNo)
  49.  
  50.                     Case vbYes: 'opens new product "entry form" and closes "sales" form
  51.                         DoCmd.OpenForm "entry form"
  52.                         DoCmd.Close acForm, "sales"
  53.  
  54.                     Case vbNo: 'closes "sales" form and goes to "main menu"
  55.                          DoCmd.OpenForm "main menu"
  56.                          DoCmd.Close acForm, "sales"
  57.  
  58.                    End Select
  59.  
  60.                 End If
  61.  
  62.             Case vbNo:
  63.                 'Do nothing
  64.  
  65.             Case Else: 'Default case to trap any errors
  66.                 'Do nothing
  67.  
  68.         End Select
  69.  
  70.  
  71.     End If
  72. End If
  73. End Sub
  74.  
  75.  
  76.  
Any ideas? I'm knew at this and I'm getting frustrated because I can't find what is wrong with this.
Thanks before hand!
Jun 16 '10 #1
2 1688
flower88
22 New Member
ok, I changed the if statements. It works find for one field on the form, newflux. but it does not work for my second field, newribbon. Any ideas would be much appreciated, thank you.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Findbtm_Click()
  2.  
  3. If Me.CompanyCell.Value = "" Then
  4. Beep
  5.     Select Case MsgBox("Cell Company is required", vbOK)
  6.     Case vbOK: 'do nothing
  7.     Case Else: 'do nothing
  8.     End Select
  9. Else
  10. Me.cellbox = Me.CompanyCell
  11. Me.newcell = Me.CompanyCell
  12. Me.firstflux = Me.Companyflux
  13. Me.firstribbon = Me.CompanyRibbon
  14.     If [firstflux] = [company name] Or [firstribbon] = [Company] Then
  15.  
  16.             DoCmd.OpenQuery "Sales"
  17.     Else
  18.      Beep
  19.         Select Case MsgBox("Combination not found. Would you like possible combinations?", vbYesNo)
  20.             Case vbYes: 'finds possible combinations
  21.             Me.newcell = Me.CompanyCell
  22.                  Beep
  23.                  Select Case MsgBox("Would you like to make Flux unknown?", vbYesNo)
  24.                       Case vbYes: 'Makes flux company unknown
  25.                           Me.Companyflux.Value = ""
  26.                           Me.newflux = Me.Companyflux
  27.  
  28.                       Case vbNo: 'leaves flux company as it is
  29.                           Me.newflux = Me.Companyflux
  30.  
  31.                       Case Else: 'default case to trap any errors
  32.                                  'do nothing
  33.                  End Select
  34.                 Beep
  35.                 Select Case MsgBox("Would you like to make Ribbon unknown?", vbYesNo)
  36.                       Case vbYes: 'makes ribbon company unknown
  37.                           Me.CompanyRibbon.Value = ""
  38.                           Me.newribbon = Me.CompanyRibbon
  39.  
  40.                       Case vbNo: 'leaves ribbon company as it is
  41.                           Me.newribbon = Me.CompanyRibbon
  42.  
  43.                       Case Else: 'defaul case to trab any errors
  44.                                   'do nothing
  45.                 End Select
  46.                 If [newflux] = "" Or [newribbon] = "" Then
  47.  
  48.                  DoCmd.OpenQuery "Sales", acViewNormal
  49.  
  50.                     ElseIf [newflux] = [company name] Or [newribbon] = [Company] Then
  51.                      DoCmd.OpenQuery "Sales", acViewNormal
  52.                      ElseIf [newflux] = "" Or [newribbon] = [Company] Then
  53.                      DoCmd.OpenQuery "Sales", acViewNormal
  54.                      ElseIf [newribbon] = "" Or [newflux] = [company name] Then
  55.                     DoCmd.OpenQuery "Sales", acViewNormal
  56.                 Else
  57.                  Beep
  58.                    Select Case MsgBox("Combination not found. Would you like to add a New Product?", vbYesNo)
  59.  
  60.                     Case vbYes: 'opens new product "entry form" and closes "sales" form
  61.                         DoCmd.OpenForm "entry form"
  62.                         DoCmd.Close acForm, "sales"
  63.  
  64.                     Case vbNo: 'closes "sales" form and goes to "main menu"
  65.                          DoCmd.OpenForm "main menu"
  66.                          DoCmd.Close acForm, "sales"
  67.  
  68.                    End Select
  69.  
  70.                 End If
  71.  
  72.  
  73.  
  74.             Case vbNo:
  75.                 'Do nothing
  76.  
  77.             Case Else: 'Default case to trap any errors
  78.                 'Do nothing
  79.  
  80.         End Select
  81.  
  82.  
  83.     End If
  84. End If
  85. End Sub
  86.  
Jun 17 '10 #2
code green
1,726 Recognized Expert Top Contributor
What do you mean by "but it does not work"?
How do you know "It works find for one field on the form, newflux"?
Also what does this mean
I don't know how to incorporate the value from companycell to the field on the query
Jun 17 '10 #3

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

Similar topics

10
3378
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
51
13285
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
2627
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
18
2476
by: Matt | last post by:
Hi, I have a probelm here: If I declare: char *p="Hello";
10
3191
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
9
2107
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
30
508
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
7
3416
by: ccarter45 | last post by:
I need to count the number of letters in a string, disregarding case. It needs to use these two methods. What's wrong? import java.util.Scanner; public class CountLetters { public static void...
4
1948
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
2
2211
by: mingke | last post by:
Hi... So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer.... So here's the part of my code I have problem with: for (i=0; i<size2;...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
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,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.