Link to home
Start Free TrialLog in
Avatar of Barca
BarcaFlag for Hong Kong

asked on

help~

i want to check what K_Check value(true/false) is.
if K_Check = false
show ID and Quality in richtextbox
what's wrong of my code?

and how to make a newline in richtextbox?

Private Sub cmdReload_Click()
    Do While Not DBrstA.EOF
        DBrstA.MoveFirst
        If DBrstA.Fields("[K_Check]").Value = False Then
            rtbOrder.Text = rtbOrder.Text + "ID" + DBrstA.Fields("[ID]").Value + "Quality" + DBrstA.Fields("[Quality]").Value
            DBrstA.Fields("[K_Check]").Value = True
        End If
        DBrstA.MoveNext
    Loop
End Sub
ASKER CERTIFIED SOLUTION
Avatar of JohnMcCann
JohnMcCann

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
add the vbCrLF Character...(oh and btw, string concatenation is done w/ the & operator, not +)

rtbOrder.Text = rtbOrder.Text & "TableID" & DBrstA.Fields("[Id]").Value & "Quality" & DBrstA.Fields("[Quality]").Value & vbCrLf
Avatar of JohnMcCann
JohnMcCann

Your code should look something like this

Private Sub cmdReload_Click()
 DBrstA.MoveFirst
 Do While Not DBrstA.EOF
  If DBrstA.Fields("[K_Check]").Value = False Then
   
   rtbOrder.Text = rtbOrder.Text & "ID = "
   rtbOrder.Text = rtbOrder.Text & DBrstA.Fields("[ID]").Value & vbTab

   rtbOrder.Text = rtbOrder.Text & "Quality = " 
   rtbOrder.Text = rtbOrder.Text & DBrstA.Fields("[Quality]").Value & vbCr

   DBrstA.Fields("[K_Check]").Value = True
  End If
  DBrstA.MoveNext
 Loop
End Sub
Avatar of Barca

ASKER

the problem still not fix
Avatar of Barca

ASKER

the problem still not fix
to check the value of your textbox do this.

Dim BoolCheck As Boolean

Private Sub Check1_Click()
If Check1.Value = vbChecked Then
BoolCheck = True
End If

If Check1.Value = vbUnchecked Then
BoolCheck = False
End If

End Sub

Private Sub Command1_Click()
If BoolCheck = True Then
    'Code
End If

If BoolCheck = False Then
    'Code
End If
End Sub
what is the field type of [K_Check].

if string, then
If DBrstA.Fields("[K_Check]").Value = "False" Then

and what's the error message you are getting if any?
Is the problem nothing happens

Then it may be the field type of K_Check is not returning a value.

If K_Check is not updating you may ned to add an update statement.

DBrstA.Fields("[K_Check]").Value = True
DBrstA.update
 

If you are still stuck

add this statement

debug.print DBrstA.Fields("[K_Check]").Value

before this one

If DBrstA.Fields("[K_Check]").Value = False Then

Run the code
Go to the debug window (Ctrl + G) read the value of K_Check.

and post it
Avatar of Barca

ASKER

K_Check is a check box
You've lost me

K_Check is a check box

and

DBrstA.Fields("[K_Check]").Value


I assume DBrstA is recorset

to check the value of your textbox do this.

Dim BoolCheck As Boolean

Private Sub Check1_Click()
If K_Check.Value = vbChecked Then
BoolCheck = True
End If

If K_Check.Value = vbUnchecked Then
BoolCheck = False
End If

End Sub

Private Sub Command1_Click()
If BoolCheck = True Then
   'Do whatever you want on true  
End If

If BoolCheck = False Then
   'Do whatever you want on false
End If

End Sub
Avatar of Barca

ASKER

the error is can't find the object

"object required"

but i am sure the name of field is true and the type is checkbox in DB(MS access).
Avatar of Barca

ASKER

i know where is my problem now


DBrstA.Fields("[K_Check]").Value

should be
DBrstA.Fields("K_Check").Value


the richtextbox still can't show another record in a new line ~
Avatar of Barca

ASKER

thanks to all
i solved all problem now