PDA

View Full Version : Solved: Form changes corrupting form



Zack Barresse
07-17-2006, 04:43 PM
Hey all, got one that's stumped me. I have a form in a database (eventually there will be many forms like this) that has criteria fields from a table that will show a report based on whatever the conditions specified in the form were (built on an SQL statement created at run-time via VBA). I've uploaded a sample DB which contains two tables, Lab_Samples (the data table) and tblOperators (a list of mathematical operators, I just created this table).

The idea of the form is for the user to specify which fields criteria he/she would like to filter the report on. I wanted to add some flexibility to the form, so instead of having each field be an exact match, I wanted to add, say,equals, does not equal, greater than, greater than or equal to, or less than, or less than or equal to. I figured I'd setup a table with this and have it as a combo box in front of each field I wanted with this ability.

I setup the VBA code already to what I think would be a working solution (don't know for sure) but after I add the combo boxes, name then and save the form, it's no longer useable. I think the form becomes corrupt. How, I'm not sure, but each time I try this the form is completely unusable afterwards. I have no idea what I'm doing. Once the objects are created on the form, the VBA code seems to compile just fine.

The form in the sample database is an original form before the adjustments I'm trying to make. If anybody has any idea how to make this better or how to get my idea to work, I'd really appreciate some pointers. Thanks for looking at it. :yes

Cosmos75
07-17-2006, 05:56 PM
Here are some changes I think need to be made.

If Len(Me.LabID.Value) <> 0 And Me.LabID.Value <> "" Then
strSQL = strSQL & "LabID = '" & Me.LabID.Value & "' AND "
End If

'Change to

If Len(Me.LabID.Value) <> 0 And Me.LabID.Value <> "" Then
strSQL = strSQL & "LabID = " & Me.LabID.Value & " AND "
End If Since LabID is an Autonumber, you don't need the "'"

If Len(Me.SampleDate.Value) <> 0 And Me.SampleDate.Value <> "" Then
strSQL = strSQL & "SampleDate = '" & Me.SampleDate.Value & "' AND "
End If

'Change to

If Len(Me.SampleDate.Value) <> 0 And Me.SampleDate.Value <> "" Then
strSQL = strSQL & "SampleDate = #" & Me.SampleDate.Value & "# AND "
End IfFor dates you need to surround them with #, e.g. #1/1/2006 12:15:00 PM#

Insofar as using your 'tblOperators', you could have a combobox for each field. Each combobox would be have 'tblOperators' as it's recordsource. Then only show the column you want to show to the user , OperatorsSign or 'OperatorsSign' or 'OperatorsText'. But when you construc the SQL be sure to use the correct combobox column that has 'OperatorsSign'

strSQL = strSQL & "LabID " & me.cboOperator_LabID.Column(1) & " " & Me.LabID.Value & " AND " I hope I understood your question correctly. Even more so, I hope my answer makes sense!

Cosmos75
07-17-2006, 06:11 PM
I took your file and added the comboboxes and code changes.

Thought it might be easier to see it than to try and decipher my post.

I hope I'm not too far off base.

Zack Barresse
07-24-2006, 02:42 PM
Nope, not far off base at all! Thanks very much Cosmos!! :D

Cosmos75
07-28-2006, 08:07 PM
Glad to be of help!
:beerchug: