Intermittant error - does not pick up contexts of tet box

majhl

Registered User.
Local time
Today, 10:44
Joined
Mar 4, 2008
Messages
89
Access 2003 on Win XP

I'm using the code below to check whether patients have abnormal metabolic syndrome.

The code works fine some of the time, but occasionally it fail to pick up on the fact that txtSEX contains either 'M' or 'F. Instead, it will inform the user that 'sex not entered etc'.

Now I know for a fact the sex is entered for all patients - it is never missing. So why does it sometimes think it is.

Any ideas anyone?

TIA for any help.

mojo



Code:
Dim metCount As Integer
metCount = 0

If IsNull(Me.txtSEX) Then
    
    MsgBox ("Sex not entered. Please complete patient details."), vbOKOnly
    Exit Sub

End If

If Not IsNull(Me.txtSEX) Then

    If Me.txtSEX = "M" Then
        
        If Me.txtWaist >= 90 Then
            
            metCount = metCount + 1
            Me.txtWaist.BackColor = 16642265
            
            If Me.txtHDLCho < 1 Then
                
                metCount = metCount + 1
                Me.txtHDLCho.BackColor = 16642265
        
            End If
                
            If Me.txtTriglycerides >= 1.7 Then
                
                metCount = metCount + 1
                Me.txtTriglycerides.BackColor = 16642265
        
            End If
            
            If Me.txtGlucose0m >= 5.6 Then
                
                metCount = metCount + 1
                Me.txtGlucose0m.BackColor = 16642265
        
            End If
            
            If (Me.txtSystolicBP >= 130 Or Me.txtDiastolicBP >= 85) Or (Me.cmbBPTreament.Value = 1) Then
                
                metCount = metCount + 1
                If Me.txtSystolicBP >= 130 Then Me.txtSystolicBP.BackColor = 16642265
                If Me.txtDiastolicBP >= 85 Then Me.txtSystolicBP.BackColor = 16642265
                If Me.cmbBPTreament.Value = 1 Then Me.cmbBPTreament.BackColor = 16642265
            
            End If
        
        End If
        
    End If
    
    If Me.txtSEX = "F" Then
       
        If Me.txtWaist >= 80 Then
            
            metCount = metCount + 1
            Me.txtWaist.BackColor = 16642265
             
            If Me.txtHDLCho < 1.3 Then
                
                metCount = metCount + 1
                Me.txtHDLCho.BackColor = 16642265
            
            End If
            
            If Me.txtTriglycerides >= 1.7 Then
                
                metCount = metCount + 1
                Me.txtTriglycerides.BackColor = 16642265
            
            End If

            If Me.txtGlucose0m >= 5.6 Then

                metCount = metCount + 1
                Me.txtGlucose0m.BackColor = 16642265
            
            End If

            If (Me.txtSystolicBP >= 130 Or Me.txtDiastolicBP >= 85) Or (Me.cmbBPTreament.Value = 1) Then

                metCount = metCount + 1
                If Me.txtSystolicBP >= 130 Then Me.txtSystolicBP.BackColor = 16642265
                If Me.txtDiastolicBP >= 85 Then Me.txtSystolicBP.BackColor = 16642265
                If Me.cmbBPTreament.Value = 1 Then Me.cmbBPTreament.BackColor = 16642265
                
            End If
            
        End If
        
    End If
    
End If

If metCount >= 3 Then
    
    Me.txtMetSynGrp = 1
    Me.txtMetSynCount = metCount
    Me.txtBTMetSyn.Visible = True
 
If you are on a new record the sex will be blank... could that be the cause?
 
Oh btw, what you are doing... I think you can do all that with Conditional formatting... eliminating a whole bunch of code!
 
If you are on a new record the sex will be blank... could that be the cause?

You are right in saying that this is a new record.

But personal details (sex, DOB, address etc.) will have been added and saved before they ever get to this stage. So the sex text box always contains either 'F' or 'M' and is never null. This is the puzzle.

What do you mean by conditional formatting btw?
 
It would depend on the event you are trigering this from. Seeing as we/I dont see the full code.

If you have it in the "on current" event or something this code will trigger multiple times per entry form. Triggering the empty field message untill finaly entered...
 
It would depend on the event you are trigering this from. Seeing as we/I dont see the full code.

If you have it in the "on current" event or something this code will trigger multiple times per entry form. Triggering the empty field message untill finaly entered...

It is called from the 'on click' event of a button on the form..
 
What do you mean by conditional formatting btw?
When you are working with (I think) 2002 and newer, in design of your form view click first on the txtSex (for example) then go to the mene and find Format => Conditional formatting

Hmz, called from the On click of a button... Sorry then I dont know except they are clicking the button at the wrong time?
Or the form is moving to a new record prior to this code fireing?
 
When you are working with (I think) 2002 and newer, in design of your form view click first on the txtSex (for example) then go to the mene and find Format => Conditional formatting

Hmz, called from the On click of a button... Sorry then I dont know except they are clicking the button at the wrong time?
Or the form is moving to a new record prior to this code fireing?

I don't think so mate.

They can't click on the button at the wrong time as the button is only enabled after they've done one or two other things. So when they click it, it can only be the 'right time', so to speak.

I'm not sure it can be moving to a new record either, unless the form magically does that by itself.

Thanks for the 'conditional formatting tip' btw!
 
Maybe if you can upload the form/db to the forum I can look at that, but... for now... I am stuck and fresh out of possible solutions.
 
Maybe if you can upload the form/db to the forum I can look at that, but... for now... I am stuck and fresh out of possible solutions.

OK. I've attached the form itself if you want to take a look.

Thanks again.
 

Attachments

it would be good to have the working version including the needed (empty) tables and queries.

So the button cmdMetSyn is enable by the button cmdDiaSta which is enabled by cmdCheckData.
The only places txtSex is used tho is in the cmdMetSyn and the LockItemsE sub.

The problem doesnt jump out at me from just the code.... Sorry :(
 
Oh, I did notice that the first button cmdCheckData doesnt check for validity of the txtSex...
I forget to mention that in my previous post.
 
Oh, I did notice that the first button cmdCheckData doesnt check for validity of the txtSex...
I forget to mention that in my previous post.

Thanks for all your efforts mate.

I'm trying to upload a complete version but the file sizes are too large.

Anything I can do about this?
 
Just delete all the data.... should compact good enough ....
 

Users who are viewing this thread

Back
Top Bottom