RascalBird
Registered User.
- Local time
 - Yesterday, 18:13
 
- Joined
 - Oct 5, 2004
 
- Messages
 - 20
 
HI
I've found a couple of similar posts but no matter what I try I can't figure out what's going wrong with my code and it's doing my head in! :banghead:
I have a form (frmInactiveBusiness) which lists old businesses. I want the user to be able to select the business and when clicking a command button, have the main Business Details form open and get populated with the Inactive Business information (if that makes sense hehe)
The code works perfectly except when I have the first record selected.
When the first record is selected the form doesn't populate at all which of course gives me a list index error (well there's nothing there).
I've put watches on and the variables seem to populate happily... any thoughts?
	
	
	
		
 I've found a couple of similar posts but no matter what I try I can't figure out what's going wrong with my code and it's doing my head in! :banghead:
I have a form (frmInactiveBusiness) which lists old businesses. I want the user to be able to select the business and when clicking a command button, have the main Business Details form open and get populated with the Inactive Business information (if that makes sense hehe)
The code works perfectly except when I have the first record selected.
When the first record is selected the form doesn't populate at all which of course gives me a list index error (well there's nothing there).
I've put watches on and the variables seem to populate happily... any thoughts?
		Code:
	
	
	Function DisplaySelectedBusiness()
    Dim i As Long
    Dim F As Form
    Dim RS As Recordset
    Dim BusNum As String
    Dim x As String
    
    Dim LResponse As Integer
    
    i = 1
    
    ' get the form and its recordset
    Set F = Forms![frmInactiveBusiness]
    Set RS = F.RecordsetClone
    
    ' move to the first record
    RS.MoveFirst
    
    ' move to the first selected record
    RS.Move F.SelTop - 1
    
    i = F.SelTop
    
    BusNum = RS![BusinessKnownName]
    
    LResponse = MsgBox("Do you wish to view '" & RS![BusinessKnownName] & "'", vbOKCancel, "View Details")
            
    If LResponse = vbCancel Then
        Exit Function
    End If
    
    x = "SELECT [ABNName],[BusinessKnownName],[BusinessABN] FROM [business] WHERE [BusinessKnownName] =  '" & BusNum & "'"
    
    DoCmd.OpenForm "frmBusinessDetails"
    Forms!frmbusinessdetails!cmb_business.SetFocus
    
    Forms!frmbusinessdetails!cmb_business.RowSource = x
    Forms!frmbusinessdetails!cmb_business.Requery
    Forms!frmbusinessdetails!cmb_business.ListIndex = 0
    
    
End Function