Hi everyone,
I want to show/hide a button on my form.
The button is for entering a new record in the table of the database.
Now when i Load the form, i want to check if there are already records in the table for a specific lanID. When there are no records, the butten has to be displayed. When there are already records for that lanID the button has to be hidden.
I have found some code to tackle that, but When i use the rs.MoveLast it hides the button when there are records, but when there are no records it gives an error that there are no records found.
Is there another way to do this? Oh I almost forgot to say that i use Access 2010
Here is the code that i use:
Thanks a lot
Wim
I want to show/hide a button on my form.
The button is for entering a new record in the table of the database.
Now when i Load the form, i want to check if there are already records in the table for a specific lanID. When there are no records, the butten has to be displayed. When there are already records for that lanID the button has to be hidden.
I have found some code to tackle that, but When i use the rs.MoveLast it hides the button when there are records, but when there are no records it gives an error that there are no records found.
Is there another way to do this? Oh I almost forgot to say that i use Access 2010
Here is the code that i use:
Code:
Private Sub Form_Load()
Dim SQL As String
Dim rs As DAO.Recordset
Dim landmeterID As String
landmeterID = [Forms]![MainForm]![LanIDTxt]
SQL = "select * from dbo_Lan_Opleiding where Id_landmeter ='" & landmeterID & "'"
Set rs = CurrentDb.OpenRecordset(SQL)
rs.MoveLast
If rs.RecordCount = 0 Then
'no rows
NewOplBtn1.Visible = True
Else
'rows returned
'BtnNewOpl1.Visible = False
NewOplBtn1.Visible = False
End If
End Sub
Wim