VS 2022 project is missing the x64 option, only has Any CPU as option - vb.net

I am at my wits end. I have a VS 2022 VB Winforms application that was working perfectly fine up until last night. Now I am getting numerous errors, most of which state "Value of type 'ComboBox()' cannot be converted to 'ComboBox()' because 'ComboBox' is not derived from 'ComboBox'". Another error staes "'DropDownWidth' is not a member of 'ComboBox'". The only thing I noticed is that the solution platform now reads "Any CPU" instead of "x64". I did not change any code that has to do with the combobox routines so the errors seemed to have come out of nowhere and the x64 solution platform is no longer an option. Any ideas? I included my code where the errors started popping up.
Public Class GlobalVar
Public Shared cmbBurgType() As ComboBox = {frmSearchNOC.cmbSearchBurgType, frmAddEntry.cmbAddBurgType}
Public Shared cmbSex() As ComboBox = {frmSearchNOC.cmbSearchSex, frmAddEntry.cmbAddSex}
Public Shared cmbRace() As ComboBox = {frmSearchNOC.cmbSearchRace, frmAddEntry.cmbAddRace}
Public Shared cmbPrefix() As ComboBox = {frmSearchNOC.cmbSearchHomeStreetPrefix, frmAddEntry.cmbAddHAddressPrefix}
Public Shared cmbSuffix() As ComboBox = {frmSearchNOC.cmbSearchHomeStreetSuffix, frmAddEntry.cmbAddHAddressSuffix}
Public Shared cmbState() As ComboBox = {frmSearchNOC.cmbSearchHomeState, frmAddEntry.cmbAddHAddressState}
Public Shared cmbPrecinct() As ComboBox = {frmSearchNOC.cmbSearchHomePrecinct, frmAddEntry.cmbAddHAddressPrecinct}
Public Shared cmbTattooLoc() As ComboBox = {frmSearchNOC.cmbSearchTattooLocation, frmAddEntry.cmbAddTattoo}
End Class
Public Sub LoadPresetDBDataCombobox(tableName As String, colName As String, objArray() As ComboBox)
Dim longestEntry As String = ""
Dim curText As String = ""
Dim sqliteReader As SQLiteDataReader
Dim sqliteReadCmd As SQLiteCommand
'clear combobox items
For Each curBox As ComboBox In objArray
curBox.Items.Clear()
Next
OpenDBConn() 'opens the database connection
sqliteReadCmd = GlobalVar.dbConn.CreateCommand()
sqliteReadCmd.CommandText = "Select " & colName & " FROM " & tableName
sqliteReader = sqliteReadCmd.ExecuteReader()
sqliteReadCmd.Dispose() 'disposes read command after it is used
'iterate through table
Using sqliteReader
While sqliteReader.Read
curText = sqliteReader.GetString(colName) 'gets the current table value for the selcted column
'places value into each combobox in array
For Each curBox As ComboBox In objArray
curBox.Items.Add(curText)
Next
'determines the length of the longest string to size to properly dize the drop down width to fit text
If (curText.Length > longestEntry.Length) Then
longestEntry = curText
End If
End While
'assigns the dropdownwidth based on an everage character width of 6 pixels
For Each curBox As ComboBox In objArray
curBox.DropDownWidth = ((longestEntry.Length * 7) + 10)
Next
sqliteReader.Close() 'close object
longestEntry = ""
End Using
CloseDBConn() 'closes the database connection
End Sub
Private Sub OpenChildForm(childForm As Form, formIndex As Integer)
If (currentChildForm IsNot Nothing) Then
currentChildForm.SendToBack()
End If
currentChildForm = childForm 'assigns passed in form as current form
childForm.TopLevel = False 'indicated the form is not top level because the main form is top level
childForm.Dock = DockStyle.Fill 'docks form to fill main form's panel
pnlMain.Controls.Add(childForm) 'adds form to the main panel on the main form
pnlMain.Tag = childForm 'associate form to main panel on main form
childForm.BringToFront() 'brings the related form to the front
childForm.Show()
Select Case formIndex
Case 0 'search noc form
'reloads various data from db into comboboxes in case items were added while on another tab
LoadPresetDBDataCombobox("BurgType", "typeName", GlobalVar.cmbBurgType) 'tattoo location
LoadPresetDBDataCombobox("Sex", "sexName", GlobalVar.cmbSex) 'sex
LoadPresetDBDataCombobox("Race", "raceName", GlobalVar.cmbRace) 'race
LoadPresetDBDataCombobox("StreetPrefix", "prefixName", GlobalVar.cmbPrefix) 'street prefix
LoadPresetDBDataCombobox("StreetSuffix", "suffixName", GlobalVar.cmbSuffix) 'street suffix
LoadPresetDBDataCombobox("State", "stateName", GlobalVar.cmbState) 'state
LoadPresetDBDataCombobox("Precinct", "precinctName", GlobalVar.cmbPrecinct) 'home precinct
LoadPresetDBDataCombobox("BodyPart", "bodyPartName", GlobalVar.cmbTattooLoc) 'tattoo location
Case 1 'browse results form
Case 2 'add entry form
'reloads various data from db into comboboxes in case items were added while on another tab
LoadPresetDBDataCombobox("BurgType", "typeName", GlobalVar.cmbBurgType) 'tattoo location
LoadPresetDBDataCombobox("Sex", "sexName", GlobalVar.cmbSex) 'sex
LoadPresetDBDataCombobox("Race", "raceName", GlobalVar.cmbRace) 'race
LoadPresetDBDataCombobox("StreetPrefix", "prefixName", GlobalVar.cmbPrefix) 'street prefix
LoadPresetDBDataCombobox("StreetSuffix", "suffixName", GlobalVar.cmbSuffix) 'street suffix
LoadPresetDBDataCombobox("State", "stateName", GlobalVar.cmbState) 'state
LoadPresetDBDataCombobox("Precinct", "precinctName", GlobalVar.cmbPrecinct) 'home precinct
LoadPresetDBDataCombobox("BodyPart", "bodyPartName", GlobalVar.cmbTattooLoc) 'tattoo location
Case 3'user settings form
Case 4 'administrator form
End Select
End Sub
Above, the errors come into play with all the GlobalVar parameters as well as the dropdownwidth call:
LoadPresetDBDataCombobox("StreetPrefix", "prefixName", GlobalVar.cmbPrefix)
curBox.DropDownWidth = ((longestEntry.Length * 7) + 10)
I tried updating VS 2022 and then reinstalled it. Neither of which worked, obviously, considering I'm asking this question. It's probably something simple and stupid but I am fried and could use some help.

Thanks to anyone who spent time reading my question. I have no idea how or when the following import got added to one of my routines but I commented it out and all the errors went away:
Imports System.Windows.Controls
I noticed it when I was copying code from my broken project to a new project to see when the errors start popping up. My best guess is that it was importing a combobox control that was different from the combobox I was trying to pass into the routine, but any comments that explain the reason are appreciated.

Related

Access 2013 - Save Value from Textbox and display again when form is opened after close

I want to save a value from textbox in a string for example and display it again when the form get's openend.
I have two textboxes PriceRangeOne and PriceRangeTwo .. The user enter here for example 20 and 40
The problem i have is that when the user switches between Form and Report the values in this textboxes are beeing deleted. How can i save them?
I tried adding a sourcecontrol to the fields but had name errors eventhough i used different names.
I tried adding this to on change and retrieve it in an onload
Dim eingabe As String = textBox1.Text or .Value
Still didn't worked. Does anyone know a way to do this?
Typically, the most efficient and reliable way to do this is to have some form auto-open when the database is opened. It could be a dashboard, or just some form with nothing else on it. Whatever you use, launch it when the database opens and then minimize it. Now you have a form that's always open, as long as the application is open. Add a couple of textboxes to this form/dashboard.
When you close your form referenced in this question, write the values of PriceRangeOne and PriceRangeTwo to the textboxes on the form I described above. Then, when you open a new form or report, you can reference the values in those textboxes. Since the form is always open, you can reference these values at any time from any form or report until you close your database.
Solved it with variables.
I declared global variables in my standart module
For example
Public PriceOne As Double
Public PriceTwo As Double
Than i did this in my form in Close() and Open():
Private Sub Form_Close()
PriceOne = Me.Field
PriceTwo = Me.FieldTwo
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Field = PriceOne
Me.FieldTwo = PriceTwo
End Sub
Works perfect!
Courtesy of How to save the last value of a textbox. | Access World Forums:
Private Sub Form_Close()
'Set the default value for textbox
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE table SET table.field = [Forms]![FormName]![Textbox] " & vbCrLf & _
"WHERE (((table.ID)=1));"
DoCmd.SetWarnings True
End Sub
Private Sub Form_Load()
'Load the default value for textbox
Me.Textbox.Value = DLookup("[field]", "[table]", "[ID]=1")
End Sub

Problems when calling a public sub

I'm facing a deadend When trying to call this sub :
Public Sub backblue(ByVal frm As Form, ByVal boxname As String)
For i = 1 To 3
CType(frm.Controls(boxname & i.ToString()), TextBox).BackColor = Color.LightBlue
Next
End Sub
with button click event :
Private Sub Button1_click and bla bla....
backblue(Me, "txb1_")
End Sub
Can anybody show me a suggestion to fix the code.
It throws "Object Referrence not set to an instance bla bla" error
For information the textbox names are :
txb1_1 , txb1_2 , txb1_3
(these are some of the many textboxes in the form that i want its bakcolor changed)
and these three textboxes are already created through designer, not from execution.
i did check the textboxes names and there's nothing wrong.
the form class is also public.
if they are the only textboxs on said form you can just loop through
For Each box as Textbox In frm.Controls
box.BackColor = Color.LightBlue
Next
This error will occur if you do not declare the Form class to be public.
Also, make sure the textbox names are really correct, although this will probably cause a different error.
If you create the textboxes during execution, make sure they are initialized with New and added to the form's Controls collection.
Try this....
Public Sub backblue(ByVal frm As Form, ByVal prefix As String)
For i = 1 To 3
Dim bxName as String = prefix & i.ToString()
Dim bx as TextBox = CType(frm.Controls(bxName), TextBox)
If bx Is Nothing Then
MsgBox("Unable to find text box " +bxName)
Dim mtch() As Control = frm.Controls.Find(bxName, true)
If mtch.Length> 0 then
bx = mtch(0)
Else
Continue For
End if
End If
Bx.BackColor = Color.LightBlue
Next
End Sub
Although, a better solution would be to either create the textboxes inside a control and pass that control to BackBlue or to create an collection that has the controls and pass that in. Which brings up what is most likely yor problem your control is contained in a sub component and thus is not in the main form control collection
Alternative, you could use either the tag of the control or create a component control that implements IExtenderProvider and add it to the form --all of the above would effectively allow you to define the controls and/how they should be handled at designtime.
It may really seem that the names generated by this loop may not be the names of the original textboxes. My suggestion is before setting this Color property verify that the names generated by this loop are indeed the actual names. Maybe output this in a messagebox:
MessageBox.Show(boxname & i.ToString()) for each loop before you set the property

Can not update List Box Selected Collection in code

I have a list box on a form being populated from a query, with items selected on basis of matching a delimited list. So sSystemString equals something like "A;B;C"
Then I load records A,B,C,D,E,F from the SQL Server DB and only A,B,C should be selected.
Is there a native way to do this in MS Access (2010). I'm using an ADP in this case.
I'm doing it via code but I can't the selected property does not reflect my changes, nor does the form.
Here's my code:
Dim rs As New ADODB.Recordset
Dim sSystemString As String
If Not IsNull(Me.OpenArgs) Then sSystemString = Me.OpenArgs
' Load this list box with SRC Systems
Call rs.Open("SELECT DISTINCT System FROM dbo.System WHERE System IS NOT NULL", _
CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly)
Do Until rs.EOF
lstSrcSystems.AddItem (rs.Fields(0))
If InStr(sSystemString, rs.Fields(0)) > 0 Then
lstSrcSystems.Selected(lstSrcSystems.ListCount - 1) = True
End If
rs.MoveNext
Loop
My code definitely hits the lstSrcSystems.Selected(lstSrcSystems.ListCount - 1) = True line.
After running this line, inspecting the property in the immediate window still returns 0 (it doesn't change). On the form, the item is also not selected.
UPDATE: I just checked my code again and now it is being updated, but the next AddItem apparently unselects it again.
I suspect I have some weird combination of properties that make this read only, but I can select items interactively, and indeed when I extract the selected items back off in code, the Selected property works as expected - i.e. I select an item on the form and it reflected in this property.
The form is unbound and is called from a button on another form with this code:
DoCmd.OpenForm "fSiteList", acNormal, , , acFormEdit, acDialog, Me.SRCSystems
The problem was actually that lstSrcSystems.AddItem (rs.Fields(0)) was resetting the Selected state. I can't find any mention of this behaviour or how to turn it off. I altered my form as follows:
Form / Data properties all blank (unbound)
List Control / Data / Control Source: blank
List Control / Data / Row Source: SELECT statement populating my list
This has the effect of populating the list but not binding the list or form to anything. (I found that binding it stopped me interactively editing data on it)
Form_Load code behind the form was changed to select already existing items:
Private Sub Form_Load()
Dim sSystemString As String
Dim iIndex As Integer
' List is bound to site list (from connections)
' Highlight those that are listed
If Not IsNull(Me.OpenArgs) Then sSystemString = Me.OpenArgs
iIndex = lstSrcSystems.ListCount
Do While iIndex > 0
If InStr(sSystemString, lstSrcSystems.ItemData(iIndex)) > 0 Then
lstSrcSystems.Selected(iIndex) = True
End If
iIndex = iIndex - 1
Loop
End Sub
I'm still curious to know whether there is a more 'built in' way to achieve this: edit a delimited string field.

create a message box on application start requiring users name then display it in the program?

I would like a message box to pop-up at the start of the program asking what the customers name is. I then want this name to be displayed in a label that i have already created.
I went to application events and entered the code below after finding a few helpful tips around the internet. I get a message box allowing me to enter the customers name, so that bit works fine. The problem comes when I try to change the label. It says that 'label4' is not declared. I'm guessing that the application events section is a completely different section from the other forms.
If anyone could explain how I would go about doing this correctly and also explain the difference between so I can learn from this that would be great.
Dim message, title, defaultValue, myvalue As String
' Set prompt.
message = "Please Enter The Customers Name"
' Set title.
title = "New Customer"
' Set default value.
defaultValue = ""
' Display message, title, and default value.
myValue = InputBox(message, title, defaultValue)
label4.text = myvalue
The controls of a form a defined locally to that form, i.e. they are private members of that form and cannot be accessed from outside. Now it depends how your code is organized. If you are calling the InputBox before opening the main form then you need a way to pass the customer name to the main form. You can do that in the constructor the main form.
' In the main form
Public Sub New(ByVal customerName As String)
InitializeComponent() ' This call is required by the Windows Form Designer.
label4.Text = customerName
End Sub
Then you can create the main form like this (see also How to find the main() entry point in a VB.Net winforms app?)
Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
...
myValue = InputBox(message, title, defaultValue)
Dim frm As Form1 = New Form1(myValue)
' Starts the application.
Application.Run(frm)
End Sub

Refresh combo box in Windows Form

HI,
This question has been asked a lot on the web but all of them seems to be confused with windows forms and asp.net forms so I had to finally come here for answer.
I have a Main form (a window form) in VB.NET which has a Combo Box to display a list of countries. A sub form activated from a "Button" on the Main form allows users to add Countries to their list. But After Adding a new entry the Combo Box on the Main form does not show the update (while it is still open). I have to exit the main form and relaunch it to see the update.
The populate function in shown below. I call this method after adding new countries but still; not good. I have used Invalidate function of combo box but of no use as well.
Any Help is appreciated. Thanks
Public Sub PopulateCountry()
Dim rsLocal As New ADODB.Recordset
Try
Dim sSQLCommand As String
Me.CountryList.Items.Clear()
'get the list of countries from the local database
sSQLCommand = " SELECT * FROM CountryList order by CountryDesc"
rsLocal.Open(sSQLCommand, cnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
'Display All the countries
While rsLocal.EOF = False
Dim Country As New modGV.cbItem
Country .ID = rsLocal.Fields("CountryID").Value
Country.name = rsLocal.Fields("Country Desc").Value.ToString.Trim
Me.CountryList.Items.Add(Country)
rsLocal.MoveNext()
End While
rsLocal.Close()
Catch ex As Exception
Debug.WriteLine("PopulateCountry: exception occurred " & ex.Description)
Finally
If rsLocal.State = ConnectionState.Open Then
rsLocal.Close()
End If
End Try
End Sub
Use object.refresh
http://www.devx.com/vb2themax/Tip/18646