T
thspimpolds
I am new to VBA and Access 03. I know java, but it does not seem to
help much for VBA. I use a database for a local store and we keep our
inventory in Access 03 per our boss. I am trying to create some code
to do a serach. What the code needs to do is take a category name of
the item from the form. Use that as a criteria for searching the
database. Next once it knows what category to look at it needs to look
at a numeric field. This field while mainly sequential has holes in is
and is not all in one grouping. I need this function to find a hole in
the scale of what i will refer to as TCR numbers. Once it has found a
hole, while in the same category it needs to display that number in a
form/msg box.
Problems I ran into:
1. I cannot get the code to enter the do while loop
2. I cannot get the form to display anything but an object, not sure if
there is a dialog box method.
3. Cannot get the search to perform right.
4. Had an infinite loop, but I believe I fixed it.
Definition of variables:
rs - current recordset object
rs2 - record set of object to put new TCR number after it was found
into a seperate table(not needed if there is a message box method, just
a workaround i tried)
tcrNum - the number which is found by the search
tcrPull - the TCR number which is pulled from the form
I apologzie ahead of time, the code might be downright awful in syntax,
approach, and coding standards.
Code:
Private Sub Search_By_Item_Number_Click()
Dim rs As Object
Dim tcrNum As Integer
Dim catName As String
Dim tcrPull As Integer
Dim db As DAO.Database
Dim rs2 As DAO.Recordset
Dim control As Boolean
Set db = CurrentDb
Set rs2 = db.OpenRecordset("tbl_TCR_Next_Number")
Set rs = Me.Recordset.clone
catName = Me.Category
tcrPull = Me.TCR_Number
control = True
Do While control = True
rs.FindFirst [Category] = catName
tcrPull = 9999
If (tcrPull <> 0) Then
tcrNum = tcrPull
Exit Do
rs.FindNext [Category] = catName
Else: Exit Do
End If
Loop
tcrNum = (tcrNum + 1)
rs.MoveNext
If (rs("TCR_Number") <> tcrNum) Then
DoCmd.OpenForm "frm_Next_TCR_Number"
' nextTCRNum (tcrNum)
End If
End Sub
help much for VBA. I use a database for a local store and we keep our
inventory in Access 03 per our boss. I am trying to create some code
to do a serach. What the code needs to do is take a category name of
the item from the form. Use that as a criteria for searching the
database. Next once it knows what category to look at it needs to look
at a numeric field. This field while mainly sequential has holes in is
and is not all in one grouping. I need this function to find a hole in
the scale of what i will refer to as TCR numbers. Once it has found a
hole, while in the same category it needs to display that number in a
form/msg box.
Problems I ran into:
1. I cannot get the code to enter the do while loop
2. I cannot get the form to display anything but an object, not sure if
there is a dialog box method.
3. Cannot get the search to perform right.
4. Had an infinite loop, but I believe I fixed it.
Definition of variables:
rs - current recordset object
rs2 - record set of object to put new TCR number after it was found
into a seperate table(not needed if there is a message box method, just
a workaround i tried)
tcrNum - the number which is found by the search
tcrPull - the TCR number which is pulled from the form
I apologzie ahead of time, the code might be downright awful in syntax,
approach, and coding standards.
Code:
Private Sub Search_By_Item_Number_Click()
Dim rs As Object
Dim tcrNum As Integer
Dim catName As String
Dim tcrPull As Integer
Dim db As DAO.Database
Dim rs2 As DAO.Recordset
Dim control As Boolean
Set db = CurrentDb
Set rs2 = db.OpenRecordset("tbl_TCR_Next_Number")
Set rs = Me.Recordset.clone
catName = Me.Category
tcrPull = Me.TCR_Number
control = True
Do While control = True
rs.FindFirst [Category] = catName
tcrPull = 9999
If (tcrPull <> 0) Then
tcrNum = tcrPull
Exit Do
rs.FindNext [Category] = catName
Else: Exit Do
End If
Loop
tcrNum = (tcrNum + 1)
rs.MoveNext
If (rs("TCR_Number") <> tcrNum) Then
DoCmd.OpenForm "frm_Next_TCR_Number"
' nextTCRNum (tcrNum)
End If
End Sub