Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 86,399 VB Programmers. There are 1,460 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

updating database with combobox

 
Reply to this topicStart new topic

updating database with combobox

emkaye
post 8 May, 2008 - 07:48 PM
Post #1


New D.I.C Head

*
Joined: 12 Aug, 2007
Posts: 28



i have a file maintenance that will add, edit, delete, etc. data

i have a combobox that autocompletes the text i entered once i typed only one letter. Below is my code for it:

CODE

Private Sub cboAgency_Change()
Dim blnAuto As Boolean
Dim strPart As String, iLoop As Integer, iStart As Integer, strItem As String
  
    If Not blnAuto And CBOAGENCY.Text <> "" Then

     iStart = CBOAGENCY.SelStart
  
        strPart = Left$(CBOAGENCY.Text, iStart)
        For iLoop = 0 To CBOAGENCY.ListCount - 1
    
            strItem = UCase$(CBOAGENCY.List(iLoop))
            If strItem Like UCase$(strPart & "*") And _
                    strItem <> UCase$(CBOAGENCY.Text) Then
        
                blnAuto = True
                CBOAGENCY.SelText = Mid$(CBOAGENCY.List(iLoop), iStart + 1)
                CBOAGENCY.SelStart = iStart  
                CBOAGENCY.SelLength = Len(CBOAGENCY.Text) - iStart
            blnAuto = False
                Exit For
            End If
      Next iLoop
    End If

End Sub

Private Sub cboAgency_KeyDown(KeyCode As Integer, Shift As Integer)

  
    If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then
        blnAuto = True
        CBOAGENCY.SelText = ""
        blnAuto = False
    ElseIf KeyCode = vbKeyReturn Then

        cboAgency_LostFocus
      
        CBOAGENCY.SelStart = Len(CBOAGENCY.Text)
        
      
        CBOAGENCY.SelLength = Len(CBOAGENCY.Text)
    
    
    End If

End Sub

Private Sub cboAgency_LostFocus()
Dim iLoop As Integer

    If CBOAGENCY.Text <> "" Then
        For iLoop = 0 To CBOAGENCY.ListCount - 1
            If UCase$(CBOAGENCY.List(iLoop)) = UCase$(CBOAGENCY.Text) Then
                blnAuto = True
                CBOAGENCY.Text = CBOAGENCY.List(iLoop)
                blnAuto = False
                Exit For
            End If
        Next iLoop
    End If

End Sub



actually, there was no problem with my code for the combobox. but i think this is one of the reasons (maybe) why i am having an error.

i am updating my database with the new data i entered in my combox. Here is my code:

CODE

Private Sub cmdUpdate_Click()
Dim UpdateRec As String


If VerEntry Then
    MsgBox "Please fill up the fields you left blank.", vbInformation, "Incomplete information detected..."
    EnableFields

Else
    
    UpdateRec = "update tblRepat set LAST_NAME='" & txtLName.Text & "', FIRST_NAME='" & txtFName.Text & "', MIDDLE_NAME='" & txtMName.Text & "', COUNTRY='" & cboCountry.Text & "', POSITION='" & cboPosition.Text & "', AGENCY='" & CBOAGENCY.Text & "' where REPAT_NO=" & Str(Val(txtRepatNo))
    Set UpdateRecRS = myConn.Execute(UpdateRec)
              
    
    MsgBox "The new record has been added succesfully.", vbInformation, "Adding new record..."
   cmdSave.Enabled = False
cmdNew.Enabled = True

If cmdNew.Enabled = True Then
    disablefields
End If
End If



End Sub



AN error stated that

SYNTAX ERROR IN UPDATE STATEMENT.

what should i change in my codes. pls help.

thanks.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:24AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month