Form record source

KingBroil

Registered User.
Local time
Yesterday, 19:55
Joined
Oct 3, 2012
Messages
41
Hi,

I have trouble understanding this:

I made a form that had as Record Source, a field from one of my database's table. Perhaps it was like that by default because I don't remember setting it myself. My form was properly functionning so far, but I decided change the Form's Record Source to "Null" so empty property field. Now the form doesn't seem to accept my DoCmd methods and returning errors when I run it. I red some documents about the Record Source of a Form, but I still can't get my head around it's use. What's the best way to make it work again?

Code:


Option Compare Database
Option Explicit

Private Sub btnAddLocation_Click()
Me.txtGeoName.Visible = True
Me.txtGeoName.SetFocus
DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cboGeoLoc_AfterUpdate()

'On Error Resume Next

' cmbSiteLoc.RowSource = 'SELECT DISTINCT SiteLocID ' & _
' "FROM tblUniqLoc " & _
' "WHERE GeoLoc = '" & cmbGeoLoc & "' " & _
' "ORDER BY PhyLoc"

End Sub

Private Sub cboGeoLoc_GotFocus()

DoCmd.RefreshRecord
Me.cboGeoLoc.Dropdown

End Sub

Private Sub txtGeoName_AfterUpdate()

Dim strSQL As String
DoCmd.RefreshRecord

strSQL = "INSERT INTO tblUniqLoc(GeoLocID)"
strSQL = strSQL & "SELECT tblGeoLoc.ID "
strSQL = strSQL & " WHERE GeoName ='" & Me.txtGeoName & "'"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

Me.cboGeoLoc.SetFocus
Me.txtGeoName.Visible = False

End Sub


Since I'm new to VBA and Access, nothing is obvious for me so I would gladly take any advices, thanks! (I have Access 2010)

KB
 
Thanks Pat,
So just to see if I understand right, on a split form, the datasheet it displays is the form's control source datasheet.

The thing with my form is that I want to use it to populate different tables. My first control was bound to the form's control source so when I wrote this:

Private Sub cboGeoLoc_GotFocus()

DoCmd.RefreshRecord 'This act on the form's control source (table) so no issues.
Me.cboGeoLoc.Dropdown

End Sub


The way that I wrote this, could it only work on the form's control source? If yes, what would be the syntax to call a method on a control that's not bound or linked in any way to the table's control source? Would it be easier to do different forms instead? Is a form without a control source something common, or it's a bad idea?

I hope I explained my issue correctly, I really apreciate your help.

KB
 

Users who are viewing this thread

Back
Top Bottom