AndyCabbages
Registered User.
- Local time
- Today, 06:00
- Joined
- Feb 15, 2010
- Messages
- 74
Hey, I am currently working on a database which was made by someone who is no longer contactable to help and my VB is not great.
Basically within one of the forms there is a 'GoTo' button, which when clicked prompts you to enter a 'Record Number' which is not as simple as being an autonumber which counts from 1 depending on the number of records. For some reason when you enter a 'Record Number' which is definitely valid it does not direct you to the coressponding record.
Below is the code for the comand relating to the 'GoTo' button:
Private Sub Command69_Click()
On Error GoTo Err_Command69_Click
Dim record As Integer
record = InputBox("Please enter the record number which you would like to go to?", "Goto Record")
Dim dbsThisDatabase As Database
Dim TableRecords As DAO.Recordset
Set dbsThisDatabase = CurrentDb()
strSQL = "SELECT Order.Record_Number, Order.Company_ID, Customers.*, Order.Contact_Name, Order.Contact_Number, Order.Order_No, Order.Tax_Point_Date, Order.INV, Order.Site, Order.Complete, Order.Discount, Order.PreparedBy FROM Customers INNER JOIN [Order] ON (Customers.Company_ID=Order.Company_ID) AND (Customers.Company_ID=Order.Company_ID) WHERE (((Order.Complete)=False)) ORDER BY Order.Record_Number"
Set TableRecords = dbsThisDatabase.OpenRecordset(strSQL)
TableRecords.MoveLast
TableRecords.MoveFirst
moveRecords = 1
isFound = False
Do While record <> TableRecords!Record_Number And moveRecords < TableRecords.RecordCount
TableRecords.MoveNext
moveRecords = moveRecords + 1
If record = TableRecords!Record_Number Then
isFound = True
End If
Loop
If isFound = True Then
DoCmd.GoToRecord , , acGoTo, moveRecords
RefreshContracts
Else
MsgBox "The record that you require cannot be found. Either its in Old contracts or doesn't exist."
End If
Err_Command69_Click:
End
Hopefully someone with a bit better understanding of VB will be able to make some sense of it
Andy
Basically within one of the forms there is a 'GoTo' button, which when clicked prompts you to enter a 'Record Number' which is not as simple as being an autonumber which counts from 1 depending on the number of records. For some reason when you enter a 'Record Number' which is definitely valid it does not direct you to the coressponding record.
Below is the code for the comand relating to the 'GoTo' button:
Private Sub Command69_Click()
On Error GoTo Err_Command69_Click
Dim record As Integer
record = InputBox("Please enter the record number which you would like to go to?", "Goto Record")
Dim dbsThisDatabase As Database
Dim TableRecords As DAO.Recordset
Set dbsThisDatabase = CurrentDb()
strSQL = "SELECT Order.Record_Number, Order.Company_ID, Customers.*, Order.Contact_Name, Order.Contact_Number, Order.Order_No, Order.Tax_Point_Date, Order.INV, Order.Site, Order.Complete, Order.Discount, Order.PreparedBy FROM Customers INNER JOIN [Order] ON (Customers.Company_ID=Order.Company_ID) AND (Customers.Company_ID=Order.Company_ID) WHERE (((Order.Complete)=False)) ORDER BY Order.Record_Number"
Set TableRecords = dbsThisDatabase.OpenRecordset(strSQL)
TableRecords.MoveLast
TableRecords.MoveFirst
moveRecords = 1
isFound = False
Do While record <> TableRecords!Record_Number And moveRecords < TableRecords.RecordCount
TableRecords.MoveNext
moveRecords = moveRecords + 1
If record = TableRecords!Record_Number Then
isFound = True
End If
Loop
If isFound = True Then
DoCmd.GoToRecord , , acGoTo, moveRecords
RefreshContracts
Else
MsgBox "The record that you require cannot be found. Either its in Old contracts or doesn't exist."
End If
Err_Command69_Click:
End
Hopefully someone with a bit better understanding of VB will be able to make some sense of it
Andy