-1

Syntax error (missing operator) in query expression 'SeriesNo (between 1and5'

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click        
    If rsa.State = 1 Then rsa.Close()

    rsa.Open("select * from Records where SeriesNo between" & Me.txtseriesfrom.Text & "and" & Me.txtseriesto.Text & "", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

    TextBox5.Text = txtseriesto.Text
    TextBox3.Text = txtseriesfrom.Text
    txtseriesto.Text = txtseriesto.Text + 1



    Do Until Val(txtseriesfrom.Text) >= Val(txtseriesto.Text)

        If rs.State = 1 Then rs.Close()
        rs.Open("select * from Transfer", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
        rs.AddNew()
        rs.Fields("SeriesNo").Value = txtseriesfrom.Text
        rs.Fields("Brand").Value = cbobrand.Text
        rs.Fields("Denomination").Value = cbodenomination.Text
        rs.Fields("Store").Value = cbostore.Text
        rs.Fields("User").Value = txtuser.Text
        rs.Fields("Date").Value = txtdate.Text
        rs.Update()

        txtseriesfrom.Text = txtseriesfrom.Text + 1
    Loop

    txtseriesto.Text = txtseriesto.Text - 1
    txtseriesfrom.Text = Val(TextBox3.Text)
    TextBox4.Text = TextBox3.Text

    TextBox5.Text = TextBox5.Text + 1
    Do Until Val(TextBox4.Text) >= Val(TextBox5.Text)
        rsa.Delete()
        rsa.MoveNext()
        TextBox4.Text = TextBox4.Text + 1
    Loop
    TextBox5.Text = TextBox5.Text - 1
    TextBox4.Text = Val(TextBox3.Text)

    MsgBox("Successfully Transfered!", vbInformation, "SAVED")


End Sub
Fabio
  • 31,528
  • 4
  • 33
  • 72

1 Answers1

0

I recommend you to save in integer variables the values of Me.txtseriesfrom.Text and Me.txtseriesto.Text then call it in the query. An example:

Dim txt_from as integer = Me.txtseriesfrom.Text

Dim txt_to as integer = Me.txtseriesto.Text

rsa.Open("select * from Records where SeriesNo between " & txt_from & " and " & txt_to & "", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

Or if the datatype of SeriesNo in your Database is Varchar:

You are missing the ' ' for texts values. The correct way should be:

rsa.Open("select * from Records where SeriesNo between '" & Me.txtseriesfrom.Text & "' and '" & Me.txtseriesto.Text & "'", cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

Also replace all txtseriesfrom.Text and txtseriesto.Text to txt_from and txt_to variable respectively.

Juanche
  • 104
  • 2
  • 8