Relative Content

Tag Archive for excelvbaforms

Check Form Controls against Data Table

I have created a form that uses TextBox and ComboBox controls.
When I save the form I want to check the Values in the Controls against the DataTable they originate in (I make changes on the form).
This worked well when I only had TextBox Controls, but when I added the ComboBox Controls and tried to rewrite the SaveData sub I started running into problems.
I’m not proficient yet at vba, and I’ve been wrestling with this for a couple of days now.
The code to build the form works, but I’ll post it anyway, along with the code for the SaveData sub which is where I’m getting the error code.
I first wrote this code without the “If TypeName(Control) = “TxtBox”” and was getting an error that Excel could not locate the object and hightlited the ComboBox code line on the Save sub. This kind of made sense to me that as it was told to look for both a TextBox and ComboBox that it would error when it first came across a TextBox and said “I can’t find ComboBox”.
So I figured I had to tell it to look at each Control and determine if it was a Text or Combo then do what needed to be done, but that isn’t working as Excel is telling me I have a Next without a For – apparently caused by having the If Statements structured the way I do (guessing). I’ve tried including Else and ElseIf but those failed also.
I need someone more proficient than I am to tell me what I’m missing.
This is the code that builds the ComboBoxes on the form:

Run time Error ’91’ Object variable or with block variable not set

I’m working in excel on a database that uses values from one sheet to update another. There is a sheet named “Line List” which contains line numbers (unique identifiers for piping) and lists information for each line such as size material etc. The other sheet, “Database” then contains a number of different tables for different instruments that can be placed on the lines such as valves and pressure regulators. I was creating two buttons on a form, one of which updates all of the instrument tables on the “Database” sheet with new line data based on the cell the user is selecting. The other button updates all tables with all of the lines. They both utilize class modules and a class function called FindMatchingRows. It originally worked, but is now giving the error “Run time Error ’91’ Object variable or with block variable not set” and debug brings me to this Line "matchingRows = oLine.FindMatchingRows(TableName, LineNum)" I will show the code bellow and would love if anyone could shed some light on the issue.