Error code "Can't finde project or library" in vba - vba

I'm making a vba project with some userforms. I want the people to click the macro button, then need to choose their initials, then by togglebutton click the weeks they want to go on holiday and then click transfer. So far i've done, that if they click one their initials, the value will be printed to a cell. The next userform (userform2), will need to look for the value, to determin wich row the values will be printed in.
But i get an error, on my Select case code.
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "CTK"
result = Something
Case Is = "MogM"
result = Something1
Case Is = "KSJI"
result = Something2
Case Is = "TSLR"
result = Something3
Case Is = "JOHQ"
result = Something4
Case Is = "OLGJ"
result = Something5
Case Is = "CBJN"
result = Something6
Case Is = "JVLK"
result = Something7
Case Is = "JFP"
result = Something8
Case Is = "EVAD"
result = Something9
Case Is = "TKUP"
result = Something10
Case Else
MsgBox ("Didn't find anyone with these init")
Range("A20").Value = result
End Select
End Sub
Private Sub ToggleButton1_Click()
End Sub
I solved the coding, but now i got a new question. Is it possible to simplify it?
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "1"
result = "CTK"
Case Is = "2"
result = "MogM"
Case Is = "3"
result = "KSJI"
Case Is = "4"
result = "TSLR"
Case Is = "5"
result = "JOHQ"
Case Is = "6"
result = "OLGJ"
Case Is = "7"
result = "CBJN"
Case Is = "8"
result = "JVLK"
Case Is = "9"
result = "JFP"
Case Is = "10"
result = "EVAD"
Case Is = "11"
result = "TKUP"
Case Else
MsgBox ("Didn't find anyone with these init")
End Select
Range("A20").Value = result
'CTK opportunities
If result = "CTK" And ToggleButton1 = True Then Range("B4").Value = "X"
If result = "CTK" And ToggleButton2 = True Then Range("C4").Value = "X"
If result = "CTK" And ToggleButton3 = True Then Range("D4").Value = "X"
If result = "CTK" And ToggleButton4 = True Then Range("E4").Value = "X"
If result = "CTK" And ToggleButton5 = True Then Range("F4").Value = "X"
If result = "CTK" And ToggleButton6 = True Then Range("G4").Value = "X"
If result = "CTK" And ToggleButton7 = True Then Range("H4").Value = "X"
If result = "CTK" And ToggleButton8 = True Then Range("I4").Value = "X"
If result = "CTK" And ToggleButton9 = True Then Range("J4").Value = "X"
If result = "CTK" And ToggleButton10 = True Then Range("K4").Value = "X"
If result = "CTK" And ToggleButton11 = True Then Range("L4").Value = "X"
If result = "CTK" And ToggleButton12 = True Then Range("M4").Value = "X"
'Next person
Unload Me
End Sub

Related

Dev Express chart Not Updating Second Time in Vb.net

For the first time when I run my window application it will successfully run, but when I change the database column and binding then it gives me an error that specific data column is not there in database; also I am make null chart datasource but it gives an error. Please help.
Dim ctrArr As Integer
Dim serCnt As Integer
Dim series1 As New Series
Dim seriesFound As Boolean = False
For serCnt = 0 To ctrChart.Series.Count - 1
ctrChart.Series(0).ArgumentDataMember = ""
ctrChart.Series(0).ValueDataMembers(0) = ""
ctrChart.Series(0).Visible = False
Next
For ctrArr = 0 To gStrYAxisParamArray.Length - 1 'deptname'
For serCnt = 0 To ctrChart.Series.Count - 1
If UCase(Trim(gStrYAxisParamArray(ctrArr))) = UCase(ctrChart.Series(serCnt).Name.ToString) Then
ctrChart.Series(serCnt).ArgumentDataMember = ""
ctrChart.Series(serCnt).ValueDataMembers(0) = ""
ctrChart.Series(serCnt).Visible = True
ctrChart.Series(serCnt).ArgumentDataMember = gxAxis
ctrChart.Series(serCnt).ValueDataMembers.Item(0) = Trim(gStrYAxisParamArray(ctrArr))
seriesFound = True
Exit For
End If
Next
If seriesFound = False Then
series1 = New Series(Trim(gStrYAxisParamArray(ctrArr)).ToString, ViewType.Bar)
'ctrChart.Series.AddRange(New Series() {series1, series2})
ctrChart.Series.Add(series1)
series1.ArgumentDataMember = ""
series1.ValueDataMembers(0) = ""
series1.Visible = True
series1.ArgumentDataMember = gxAxis
series1.Label.Border.Visible = False
series1.ValueDataMembers(0) = Trim(gStrYAxisParamArray(ctrArr))
series1.LegendText = Trim(gStrYAxisParamArray(ctrArr).ToString)
End If
seriesFound = False
Next
cmbSeries.Items.Clear()
For ctrArr = 0 To ChrtStockDept.Series.Count - 1
With cmbSeries.Items
cmbSeries.Items.Add(ChrtStockDept.Series(ctrArr).Name.ToString)
End With
Next

Case vba is skipping over the correct case

Dim score As Variant
score = Range("KPI!A6").Value
Select Case score
Case score = "January"
Columns("D:N").EntireColumn.Hidden = True
Case score = "February"
Columns("C:C,E:N").EntireColumn.Hidden = True
Case score = "March"
Columns("C:D,F:N").EntireColumn.Hidden = True
Case score = "April"
Columns("C:E,G:N").EntireColumn.Hidden = True
Case score = "May"
Columns("C:F,H:N").EntireColumn.Hidden = True
Case score = "June"
Columns("C:G,I:N").EntireColumn.Hidden = True
Case score = "July"
Columns("C:H,J:N").EntireColumn.Hidden = True
Case score = "August"
Columns("C:I,K:N").EntireColumn.Hidden = True
Case score = "September"
Columns("C:J,L:N").EntireColumn.Hidden = True
Case score = "October"
Columns("C:K,M:N").EntireColumn.Hidden = True
Case score = "November"
Columns("C:L,N:N").EntireColumn.Hidden = True
Case score = "December"
Columns("C:M").EntireColumn.Hidden = True
End Select
End Sub
Hey all! This is my first question, so hopefully I'm not doing things incorrectly. In any case (pun intended here).... I have some relatively basic "case" code that should be looking at the cell value of A6 and hiding columns based on which month is showing. I'm having a hard time figuring out why it's skipping over the correct case (in this instance "May"). I can step through the code, but it is not stopping to perform the hide columns part. It just keeps going, checking each case and eventually hits the end of the sub and ends. I don't receive any errors, it just doesn't catch the correct value and perform the action. Any help would be appreciated. Thanks!
If score is a string such as January then score = "January" (etc) will return True (or False). True (or False) won't be equal to the value of score (i.e. "January"), so therefore none of your tests will be satisfied.
You probably meant to say:
Dim score As Variant
score = Range("KPI!A6").Value
Select Case score
Case "January"
Columns("D:N").EntireColumn.Hidden = True
Case "February"
Columns("C:C,E:N").EntireColumn.Hidden = True
Case "March"
Columns("C:D,F:N").EntireColumn.Hidden = True
Case "April"
Columns("C:E,G:N").EntireColumn.Hidden = True
Case "May"
Columns("C:F,H:N").EntireColumn.Hidden = True
Case "June"
Columns("C:G,I:N").EntireColumn.Hidden = True
Case "July"
Columns("C:H,J:N").EntireColumn.Hidden = True
Case "August"
Columns("C:I,K:N").EntireColumn.Hidden = True
Case "September"
Columns("C:J,L:N").EntireColumn.Hidden = True
Case "October"
Columns("C:K,M:N").EntireColumn.Hidden = True
Case "November"
Columns("C:L,N:N").EntireColumn.Hidden = True
Case "December"
Columns("C:M").EntireColumn.Hidden = True
End Select
End Sub
which will compare the value of score to each of the literal strings "January", "February", etc, in turn and execute the first Case where the comparison is True.
Or, as Jeeped suggests, to avoid removing score = from each of your Case statements you could use:
Dim score As Variant
score = Range("KPI!A6").Value
Select Case True
Case score = "January"
Columns("D:N").EntireColumn.Hidden = True
Case score = "February"
Columns("C:C,E:N").EntireColumn.Hidden = True
Case score = "March"
Columns("C:D,F:N").EntireColumn.Hidden = True
Case score = "April"
Columns("C:E,G:N").EntireColumn.Hidden = True
Case score = "May"
Columns("C:F,H:N").EntireColumn.Hidden = True
Case score = "June"
Columns("C:G,I:N").EntireColumn.Hidden = True
Case score = "July"
Columns("C:H,J:N").EntireColumn.Hidden = True
Case score = "August"
Columns("C:I,K:N").EntireColumn.Hidden = True
Case score = "September"
Columns("C:J,L:N").EntireColumn.Hidden = True
Case score = "October"
Columns("C:K,M:N").EntireColumn.Hidden = True
Case score = "November"
Columns("C:L,N:N").EntireColumn.Hidden = True
Case score = "December"
Columns("C:M").EntireColumn.Hidden = True
End Select
End Sub
which will compare the value True to each of the logical expressions such as score = January, score = February, etc, in turn and execute the first Case where the comparison to True returns True.
The Select Case statement is just a prettied-up If statement. The following Select Case statement
Select Case x
Case y
DoSomething
Case z
DoSomethingElse
End Select
is equivalent to the following If statement
If x = y Then
DoSomething
ElseIf x = z Then
DoSomethingElse
End If
No need to do the Select Case:
Dim score As Variant
With Worksheets("KPI")
score = .Range("A6").Value
'if score is a date remove this next line
score = DateValue(1 & " " & score & " 2017")
.Columns("C:N").Hidden = True
.Columns(Month(score) + 2).Hidden = False
End With

VBA - IF statements with AND not working

Any help would be great. I cant seem to get the ELSEIF with the AND to work.
I am using a user-form. When they press the button the user form appears with check boxes. I am having trouble when both check boxes are checked. individually they work fine,
I am not sure what i am doing wrong. any help would be greatly appreciated
If Intact.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
End With
ElseIf Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storCompugen
End With
ElseIf Intact.Value And Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
storDate1 = Sheets("escalation").Cells(Selection.Row, 2)
storProject1 = Sheets("escalation").Cells(Selection.Row, 3)
StorBill1 = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
.formfields("text5").Result = storDate1
.formfields("Text6").Result = storProject1
.formfields("Text7").Result = StorBill1
.formfields("Text8").Result = storCompugen
End With
End If
Thanks in advance
Try changing the order. Otherwise as soon as one condition is met the If clause is exited.
If Intact.Value And Compugen.Value Then
'code
ElseIf Intact.Value Then
'code
ElseIf Compugen.Value Then
'code
End If
If Intact.Value = True is true then the first, not the third block will run.
Similarly if Intact.Value = True is not true and Compugen.Value = True is true, then the second block will run.
So you can see that the third block is not reachable.
The solution is to put the Intact.Value = True And Compugen.Value = True case first in the group.
Finally, Foo.Value = True is a tautology of the simpler Foo.Value. You can drop all the explicit = True comparisons.

Adding Between 0 and 3 Databases to a UserControl

I am trying to add a property called NumDBsToDisplay that gives the option of selecting between 0 and 3 databases to be displayed on my custom control. I can't get the property to show up in the designer, am I missing something here?
Here's the code:
Public Property NumDBsToDisplay(ByVal i As Integer) As Integer
Get
Dim count As Integer = 0
If cboPridb.Visible = True Then
count += 1
End If
If cboSecdb.Visible = True Then
count += 1
End If
If cboTridb.Visible = True Then
count += 1
End If
Return count
End Get
Set(ByVal value As Integer)
If value = 0 Then
cboPridb.Visible = False
cboSecdb.Visible = False
cboTridb.Visible = False
ElseIf value = 1 Then
lblPridB.Text = "Primary Database"
cboPridb.Visible = True
cboSecdb.Visible = False
cboTridb.Visible = False
ElseIf value = 2 Then
lblPridB.Text = "Primary Database"
lblSecDB.Text = "Secondary Database"
cboPridb.Visible = True
cboSecdb.Visible = True
cboTridb.Visible = False
Else
lblPridB.Text = "Primary Database"
lblSecDB.Width = 131
lblSecDB.Text = "Secondary Database"
lblTriDB.Text = "Tertiary Database"
cboPridb.Visible = True
cboSecdb.Visible = True
cboTridb.Visible = True
End If
End Set
End Property
Thank you for the help.

ScriptManager.RegisterClientScriptBlock hidden controls at runtime

I need your help. I would like to understand why when running ScriptManager.RegisterClientScriptBlock the controls of my page disappear and reappear only after confirmation of Ok?
Protected Sub ddlDeckFittingCategory_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlDeckFittingCategory.SelectedIndexChanged
If txbNumberofColumns.Text = "" Or Me.txbShellDiameter.Text = "" Then
ScriptManager.RegisterClientScriptBlock(Me.Page, Page.GetType, "alert", "alert('Informe o valor do Diâmetro do Casco (m)!');", True)
ddlDeckFittingCategory.SelectedValue = -1
Else
If Request("TipoTela") = 1 Then
If ddlDeckFittingCategory.SelectedValue = "Typical" Then
objFinttings_temp.IncluirFittingsTempTQIFLTTipico(Session("cod_usuario_usu"))
'objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(CType(txbNumberofColumns.Text, Double))
objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(txbNumberofColumns.Text)
tbFittingsFonte.Visible = True
tbFittingsFonte.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
Dim dvConsultarCodFonteEmFittingsTempPorUsuario As DataView = objFinttings_temp.ConsultarCodFonteEmFittingsTempPorUsuario(Session("cod_usuario_usu"))
Session("cod_fonte_fon") = dvConsultarCodFonteEmFittingsTempPorUsuario.Table.Rows(0)("cod_fonte_fon")
Session("ddlDeckFittingCategory") = ddlDeckFittingCategory.SelectedValue
Else
objFinttings_temp.IncluirFittingsTQIFLTDetalhado(0)
tbFittings.Visible = True
tbFittings.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
End If
GrvFittingsFonte.DataBind()
Else
If ddlDeckFittingCategory.SelectedValue = "Typical" Then
objFinttings_temp.IncluirFittingsTempTQIFLTTipico(Session("cod_usuario_usu"))
'objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(CType(txbNumberofColumns.Text, Double))
objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(txbNumberofColumns.Text)
tbFittingsFonte.Visible = True
tbFittingsFonte.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
Else
objFinttings_temp.IncluirFittingsTQIFLTDetalhado(Session("cod_fonte_fon"))
tbFittings.Visible = True
tbFittings.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
End If
GrvFittingsFonte.DataBind()
If ddlSelfSupportingRoof.SelectedValue = 1 Or ddlSelfSupportingRoof.SelectedValue = "-1" Then
txbNumberofColumns.Enabled = False
rvNumColuna.Visible = False
ddlEffectiveColumnDiameter.Enabled = False
rvDiametroEfetivoColuna.Visible = False
Else
txbNumberofColumns.Enabled = True
rvNumColuna.Visible = True
ddlEffectiveColumnDiameter.Enabled = True
rvDiametroEfetivoColuna.Visible = True
End If
End If
End If
End Sub
enter code here
use Page.ClientScript.RegisterStartupScript()
it will run after the page loads.