Piker
01-29-2008, 07:41 PM
OK. I have a few questions all relating to the same problem. The first one is the most important because its not working at all, so if thats the only one that gets solved i will still be extremelly grateful. The others can be done a better way than i have implemented but i just dont really know how.
1. I have a form with 2 combo boxes, i want to take the key value from those combo's and use them in an SQL string to query a specific set of records from my database.
Basically i get errors, i know im calling the functions incorrectly but cannot find on the net how to fix it.
here is my code:
Private Sub DwgTypeCmb_AfterUpdate()
Dim temp1, temp2, temp3 As String
Dim rsCount As Integer
DwgNumberTxt.Value = DwgSysNoCmb.Column(1) & "-" & DwgTypeCmb.Column(1) & "-"
temp1 = DwgSysNoCmb.Column(0) 'Combo to select the System Number
temp2 = DwgTypeCmb.Column(0) 'Combo to select the Drawing Type
Dim dbase As Database
Dim rs As DAO.Recordset
Dim SQLString As String
Set dbase = CurrentDb()
SQLString = "SELECT Drawings.Sequence FROM Drawings WHERE (((Drawings.System_ID) = '" & temp1 & "') And ((Drawings.Drawing_Type) = '" & temp2 & "')) ORDER BY Drawings.Sequence DESC"
MsgBox (SQLString)
Set rs = db.OpenRecordset(SQLString)
rsCount = rs.RecordCount
If rs.EOF = False Then 'I want a drawing number 123-XX-1111
Dim i As Integer 'this should as leading zeroes if number of
temp3 = Trim(Str(rsCount)) 'records is less than 1000
For i = Len(temp3) To Length - 1
temp3 = "0" & temp3
Next
Else
temp3 = "Not found"
End If
DwgNumberTxt.Value = DwgNumberTxt.Value & temp3
End Sub
Just to explain i select the system number for the first combo, then the drawing type from the second, thats when this code should run, it queries the number of records that match both the system number and the drawing type, then creates a drawing number that is incremented by 1 from the last number used.
Sorry if my description is a bit long, but my code is pretty messy so i wanted to clear it up a bit.
1. I have a form with 2 combo boxes, i want to take the key value from those combo's and use them in an SQL string to query a specific set of records from my database.
Basically i get errors, i know im calling the functions incorrectly but cannot find on the net how to fix it.
here is my code:
Private Sub DwgTypeCmb_AfterUpdate()
Dim temp1, temp2, temp3 As String
Dim rsCount As Integer
DwgNumberTxt.Value = DwgSysNoCmb.Column(1) & "-" & DwgTypeCmb.Column(1) & "-"
temp1 = DwgSysNoCmb.Column(0) 'Combo to select the System Number
temp2 = DwgTypeCmb.Column(0) 'Combo to select the Drawing Type
Dim dbase As Database
Dim rs As DAO.Recordset
Dim SQLString As String
Set dbase = CurrentDb()
SQLString = "SELECT Drawings.Sequence FROM Drawings WHERE (((Drawings.System_ID) = '" & temp1 & "') And ((Drawings.Drawing_Type) = '" & temp2 & "')) ORDER BY Drawings.Sequence DESC"
MsgBox (SQLString)
Set rs = db.OpenRecordset(SQLString)
rsCount = rs.RecordCount
If rs.EOF = False Then 'I want a drawing number 123-XX-1111
Dim i As Integer 'this should as leading zeroes if number of
temp3 = Trim(Str(rsCount)) 'records is less than 1000
For i = Len(temp3) To Length - 1
temp3 = "0" & temp3
Next
Else
temp3 = "Not found"
End If
DwgNumberTxt.Value = DwgNumberTxt.Value & temp3
End Sub
Just to explain i select the system number for the first combo, then the drawing type from the second, thats when this code should run, it queries the number of records that match both the system number and the drawing type, then creates a drawing number that is incremented by 1 from the last number used.
Sorry if my description is a bit long, but my code is pretty messy so i wanted to clear it up a bit.