n1a2v3i3n
Programmer
- Jan 19, 2009
- 18
I want to display records from the database. I am trying to move from last to first. I have written the code as below:
Private Sub cmdPrevious_Click()
rs.MovePrevious
If rs.BOF = True Then
MsgBox "This is the First record.", vbExclamation, "Note it..."
rs.MoveFirst
End If
vecno.Text = rs(1)
ecmsno.Text = rs(2)
ecmpno.Text = rs(3)
emno.Text = rs(8)
epno.Text = rs(7)
Dim sSQL As String
Dim lKey As Long
Dim lSize As Long
Dim varChunk() As Byte
Dim lOffset As Long
Dim sPath As String
Dim nHandle As Integer
Dim iChunks As Integer
Dim nFragmentOffset As Integer
Dim i As Integer
Dim sFile As String
Screen.MousePointer = vbHourglass
rsImage.MovePrevious
If Not rsImage.BOF Then
MsgBox "not BOF"
nHandle = FreeFile
sPath = App.Path
sFile = sPath & "\output.bin"
Open sFile For Binary Access Write As nHandle
lSize = rsImage("a_image").FieldSize
iChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
ReDim Buffer(nFragmentOffset) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, nFragmentOffset)
Put nHandle, , varChunk()
lOffset = nFragmentOffset
For i = 1 To iChunks
ReDim varChunk(conChunkSize) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, conChunkSize)
Put nHandle, , varChunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
Else
MsgBox "First rec"
rsImage.MoveFirst
nHandle = FreeFile
sPath = App.Path
sFile = sPath & "\output.bin"
Open sFile For Binary Access Write As nHandle
lSize = rsImage("a_image").FieldSize
iChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
ReDim Buffer(nFragmentOffset) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, nFragmentOffset)
Put nHandle, , varChunk()
lOffset = nFragmentOffset
For i = 1 To iChunks
ReDim varChunk(conChunkSize) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, conChunkSize)
Put nHandle, , varChunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
End If
End Sub
In here the records are moving but the images are not moving to previous record.
Also i want to fit the image to the picture box on the form.
Private Sub cmdPrevious_Click()
rs.MovePrevious
If rs.BOF = True Then
MsgBox "This is the First record.", vbExclamation, "Note it..."
rs.MoveFirst
End If
vecno.Text = rs(1)
ecmsno.Text = rs(2)
ecmpno.Text = rs(3)
emno.Text = rs(8)
epno.Text = rs(7)
Dim sSQL As String
Dim lKey As Long
Dim lSize As Long
Dim varChunk() As Byte
Dim lOffset As Long
Dim sPath As String
Dim nHandle As Integer
Dim iChunks As Integer
Dim nFragmentOffset As Integer
Dim i As Integer
Dim sFile As String
Screen.MousePointer = vbHourglass
rsImage.MovePrevious
If Not rsImage.BOF Then
MsgBox "not BOF"
nHandle = FreeFile
sPath = App.Path
sFile = sPath & "\output.bin"
Open sFile For Binary Access Write As nHandle
lSize = rsImage("a_image").FieldSize
iChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
ReDim Buffer(nFragmentOffset) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, nFragmentOffset)
Put nHandle, , varChunk()
lOffset = nFragmentOffset
For i = 1 To iChunks
ReDim varChunk(conChunkSize) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, conChunkSize)
Put nHandle, , varChunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
Else
MsgBox "First rec"
rsImage.MoveFirst
nHandle = FreeFile
sPath = App.Path
sFile = sPath & "\output.bin"
Open sFile For Binary Access Write As nHandle
lSize = rsImage("a_image").FieldSize
iChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize
ReDim Buffer(nFragmentOffset) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, nFragmentOffset)
Put nHandle, , varChunk()
lOffset = nFragmentOffset
For i = 1 To iChunks
ReDim varChunk(conChunkSize) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, conChunkSize)
Put nHandle, , varChunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
End If
End Sub
In here the records are moving but the images are not moving to previous record.
Also i want to fit the image to the picture box on the form.